2024每日刷题(121)
Leetcode—2639. 查询网格图中每一列的宽度
实现代码
class Solution {
public:int func(int num) {if(num == 0) {return 1;}int len = 0;while(num != 0) {len++;num /= 10;}return len;}vector<int> findColumnWidth(vector<vector<int>>& grid) {const int m = grid.size();const int n = grid[0].size();vector<int> ans;for(int j = 0; j < n; j++) {int maxlen = 0;for(int i = 0; i < m; i++) {int len = func(abs(grid[i][j]));if(grid[i][j] < 0) {len++;}maxlen = maxlen > len ? maxlen: len;}ans.push_back(maxlen);}return ans;}
};
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!