In a two-dimensional array (each one-dimensional array is the same length), 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.
functionFind (target, array) {//you can find the corresponding element from the lower left corner of the two-dimensional array, if the target value //is greater than the number of the lower left corner of the two-dimensional array, the target value is not in the first column //if the target value is less than the lower-left corner of the two-D array, then the target value is not in the last row varRownum=array.length-1; varColnum=array[0].length-1; //the number of the lower left corner of the two-dimensional array is represented as array[row-1][0] varI=rownum,j=0; //need to have a loop while(I>=0 && j<=colnum) { if(target==Array[i][j]) { return true; } if(array[i][j]>target) {i--; //continue;//instructions to end this cycle, go to the next loop //description if ARRAY[I][J] will end this cycle if it is greater than target and then row--, it will have no effect on Col.}Else if(array[i][j]<target) {J++; //continue; } } return false; }
Find from a two-dimensional array (i)