countNegatives: 73 ms, faster than 67.53% of solutions
var countNegatives = function(grid) {
        let count = 0;
        const m = grid.length-1; const n=grid[0].length-1;
        for(let r=m; r>=0; r--) {
            for(let c=n; c>=0; c--) {
                if(grid[r][c]<0) {
                    count++;
                }
                if(grid[r][c-1]>0) {
                    break;
                }
            }
        }
        return count;
};
Comments (0)