[Programming questions] finding in a two-dimensional array
in a two-dimensional array, each row is ordered in ascending order from left to right, and each column is sorted in ascending order from top to bottom. Complete a function, enter a two-dimensional array and an integer to determine if the array contains the integer
Complete by code:
Public classArrayfind { Public Static voidMain (string[] args) {inta[][]={{1,2,3},{4,5,6},{7,8,9}}; System.out.println (Find (A,7)); } Public Static Boolean Find(int[][]array,inttarget) {//Core functionBooleanFound =false; intRowNum =Array.Length; intColnum = array[0].length; intRow = 0; intCol = 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++; } ElseCol--; } } returnfound; }}
Sword Offer_ quickly find out if a target exists in an incremental two-dimensional array