作者:
Rushia (みけねこ的鼻屎)
2023-06-08 10:52:18https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/description/
1351. Count Negative Numbers in a Sorted Matrix
給你一個排序好的 Matrix,找出該 Matrix 有幾個非正整數。
Example 1:
Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
Output: 8
Explanation: There are 8 negatives number in the matrix.
Example 2:
Input: grid = [[3,2],[1,0]]
Output: 0
思路:
1.從每一列的最右邊往左找,如果小於0 count就遞增,否則跳出處理下一列。
Java Code: