标签:一个 int off 剑指offer 注意 system out 下标 color
class Solution { public boolean Find(int target, int [][] array) { if(array.length == 0 ) return false; //从左下角开始 int r = array.length - 1; int l = 0; while(true) { if(r<0 || l>array[0].length-1) return false; if(array[r][l] > target) { r--; }else if(array[r][l] < target) { l++; }else { return true; } } } } public class Main { public static void main(String[] args) { int a = 16; int[][] array = {}; Solution so = new Solution(); System.out.println(so.Find(16,array)); } }
class Solution { public boolean Find(int target, int [][] array) { for(int i = 0; i < array.length; i++) { int l = 0; if(array.length<=0) return false; if(array[0].length<=0) return false; int r = array[0].length-1; while(l<=r) { int mid = (l+r)/2; if(target>array[i][mid]) { l = mid+1; } else if(target<array[i][mid]) { r = mid-1; } else return true; } } return false; } } public class Main { public static void main(String[] args) { int a = 16; int[][] array = {{1,3,4},{3,16,1}}; Solution so = new Solution(); System.out.println(so.Find(16,array)); } }
标签:一个 int off 剑指offer 注意 system out 下标 color
原文地址:http://www.cnblogs.com/zhangmingzhao/p/7788971.html