我是在力扣提交答案出现的这个问题,百思不得其解答,最后看的力扣的评论区才发现的,原来力扣测试用的是一个空数组,而我没有排除这种情况导致数组索引越界了。
解决方法
加上下面的代码,先进行判断数组是否为空
class Solution {
public boolean findNumberIn2DArray(int[][] matrix, int target) {
if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
return false;
}
}
}