1351. 统计有序矩阵中的负数
题目链接:1351. 统计有序矩阵中的负数
代码如下:
cpp
class Solution {
public:
int countNegatives(vector<vector<int>>& grid) {
int res = 0;
int m=grid.size();
int n=grid[0].size();
for (int i = 0;i < m;i++) {
for (int j = 0;j < n;j++) {
if (grid[i][j] < 0) {
res++;
}
}
}
return res;
}
};