[leetcode]5340. 统计有序矩阵中的负数

在这里插入图片描述
在这里插入图片描述

class Solution {
public:
    int countNegatives(vector<vector<int>>& grid) {
        int res = 0;
        for(int i=0; i <grid.size(); i++)
        {
            for(int j= 0; j < grid[0].size(); j++)
            {
                if(grid[i][j] < 0)
                {
                    res++;
                }
            }
        }
        return res;
    }
};
发布了179 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40691051/article/details/104349993