LC 1351. Count Negative Numbers in a Sorted Matrix

Nilanjan Deb · April 5, 2020

This is my CPP solution.

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


Dicussion Forum