Note: This article refers to the second edition of "Jian-point offer" topic:
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. Please complete a function,
Enter such a two-dimensional array and an integer to determine if the array contains the integer.
1. Analysis
First, select the number in the upper-right corner of the array. If the number is equal to the number you are looking for, the lookup process ends, if the number is greater than the array you are looking for, the column that contains the number is excluded, and if the number is less than the number you are looking for, the row that contains the number is excluded. That is, if the number you are looking for is not in the upper-right corner of the array, each time you exclude a row or column from the array's look-up, each step narrows the search until you find the number you are looking for, or the lookup range is empty.
2. Example
Returns True if the number 7 is found in a two-dimensional array, or false if it is not found.
The lookup process is as follows:
3, Java Code Implementation and operation of the following:
The sword refers to the offer:2. Two-D array lookup (Java edition)