题解 | #二维数组中的查找#
二维数组中的查找
http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
public class Solution { public boolean Find(int target, int [][] array) { int m = array.length; int n = array[0].length; if (m == 0 || n == 0) return false; for(int i = 0; i < m; i++){ if(target >= array[i][0] && target <= array[i][n-1]){ int left = 0; int right = n-1; while(left <= right){ int mid = (left + right) / 2; if(target == array[i][mid]) return true; if(target < array[i][mid]) right = mid - 1; if(target > array[i][mid]) left = mid + 1; } } } return false; } }