package javaTrain; public class offer3 { public static void main(String args[]) { int[][] a = {{0,1,2,3},{1,2,3,4},{2,3,4,5},{6,7,8,9}}; System.out.println(find(a,10)); } public static boolean find(int[][] a,int num) { if(a == null) return false; int n = a.length; int m = a[0].length; int i = 0; int j = m-1; while(i < n && j >= 0) { if(a[i][j] == num) return true; else if(a[i][j] > num) --j; else ++i; } return false; } }
原文地址:http://blog.csdn.net/ymzmdx/article/details/45008903