输入:grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
输出:8
解释:矩阵中共有 8 个负数。...输入:grid = [[1,-1],[-1,-1]] 输出:3
class Solution {
public int countNegatives(int[][] arr...}
}
return count;
}
}
第一个for循环控制行,...第二个while循环来二分查找, 让Low=high 结束找到第一个负数开始出现的下标(此时 Low=high=第一个负数下标), 让count+(总长度-low)