Count Negative Numbers in a Sorted Matrix LeetCode solution in Java

1
class Solution {
2
public int countNegatives(int[][] grid) {
3
int m = grid.length;
4
int n = grid[0].length;
5
int c = 0;
6
int count = 0;
7
int r = m - 1;
8
while (r >= 0 && c < n) {
9
if (grid[r][c] < 0) {
10
r--;
11
count += n - c;
12
} else {
13
c++;
14
}
15
}
16
return count;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0