Given a
m x n
matrixgrid
which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers ingrid
.
Constraints:
m == grid.length
n == grid[i].length
1 <= m, n <= 100
-100 <= grid[i][j] <= 100
Follow up: Could you find an
O(n + m)
solution?
給予一個
m x n
並且欄與列都以非遞增順序排序的矩陣grid
,回傳grid
中非負數的數量。
限制:
m == grid.length
n == grid[i].length
1 <= m, n <= 100
-100 <= grid[i][j] <= 100
進階題:你可以找到一個
O(n + m)
的解法嗎?
O(m * n)
j
其實不需要重置n + m
,達到 O(n + m)
LeetCode
C++