public static boolean Find(int target, int [][] array) { if(array==null || (array.length==1 && array[0].length==0)){ return false; } int index = -1; for (int i = 0; i < array.length; i++) { Integer first = array[i][0]; if(first == target){ return true; } if(first>target){ index = i; break; } index = i; } if(index <= 0){ return false; } int rowIndex = -1; for (int i = index; i >= 0; i--) { int[] rows = array[i]; rowIndex = rows.length - 1; for (int j = 0; j <= rowIndex; j++) { Integer value = rows[j]; if(value == target){ return true; } if(value>target){ rowIndex = j; continue; } } } return false; }
牛客网刷题 二维数组中的查找
猜你喜欢
转载自www.cnblogs.com/yongjixl/p/11957826.html
今日推荐
周排行