Home > Back-end >  2020-11-15: write code: orderly rows, columns and orderly two-dimensional array, num, find return tr
2020-11-15: write code: orderly rows, columns and orderly two-dimensional array, num, find return tr

Time:11-16

2020-11-15: write code: orderly rows, columns and orderly two-dimensional array, num, find return true, otherwise false? # # f greatly architects a daily topic

CodePudding user response:

 
Search for
in the upper rightPublic Boolean find (int num, int [] [] array) {
Int rows=array. The length;
If (rows==0) {
return false;
}
Int cols=array [0]. Length;
If (cols==0) {
return false;
}
//right
Int row=0;
Int col=cols - 1;
While (row=0) {
If (array [row] [col] Row++;
} else if (array [row] [col] & gt; Num) {
Col -;
} else {
return true;
}
}
return false;
}