본문 바로가기
IT/알고리즘

34] Leetcode 1351. Count Negative Numbers in a Sorted Matrix

by 깻잎쌈 2020. 7. 19.
반응형

 

 

Count Negative Numbers in a Sorted Matrix - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

grid.size()  vs grid[0].size()

class Solution {
public:
    int countNegatives(vector<vector<int>>& grid) {
        int ans=0;
        for(int i = 0;i<grid.size();i++)
            for(int j = 0;j<grid[0].size();j++)
                if(grid[i][j]<0)
                    ans++;
        
        return ans;
    }
};

 

반응형

댓글