The sword refers to the search in the 1:2-D array

Source: Internet
Author: User


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.


This is a sequential two-dimensional array that can be searched from the lower right corner. you should pay attention to the lower limit of the array, don't forget to subtract one

 Public classSolution { Public BooleanFind (intTargetint[] Array) {            intRow = 0; intCol = array[0].length-1 ;  while(Row <= array.length-1 && Col >= 0){            if(target = =Array[row][col]) {                return true; }Else if(Target >Array[row][col]) {Row++; }Else{col--; }                   }         return false; }}

The sword refers to the search in the 1:2-D array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.