标签:
public class ArrayFind { public static void main(String[] args){ int a[][]={{1,2,3},{4,5,6},{7,8,9}}; System.out.println(Find(a,7)); } public static boolean Find(int [][]array,int target){ // 核心函数 boolean found = false; int rowNum = array.length; int colNum = array[0].length; int row = 0; int col = colNum - 1; if(array!=null && rowNum>0 && colNum>0){ while(row < rowNum && col>=0){ if(array[row][col]==target){ found=true; break; } else if(array[row][col]<target){ row++; } else col--; } } return found; } }
标签:
原文地址:http://www.cnblogs.com/snowwhite/p/4747126.html