https://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: