Count Negative Numbers in a Sorted Matrix faster than 100% JAVA
class Solution {
    public int countNegatives(int[][] grid) {
        int lastrow= grid.length-1,lastcol=grid[0].length,count=0,j=0,point=0;
        for(int i=lastrow;i>=0;i--){
             j=point;
            while(j<lastcol)
                if(grid[i][j]<0){
                    count= count+grid[0].length-j;
                    point=j;
                    j=lastcol;
                }
            else j++;  
                     
        }
        return count;
    }
}
Comments (0)