二位数组中的查找
程序员文章站
2022-08-28 12:53:26
1 public class Solution 2 { 3 public bool Find(int target, int[][] array) 4 { 5 if (array != null) 6 { 7 int rowCnt = array.Length - 1; 8 int colCnt = ......
1 public class solution 2 { 3 public bool find(int target, int[][] array) 4 { 5 if (array != null) 6 { 7 int rowcnt = array.length - 1; 8 int colcnt = array[0].length - 1; 9 10 int row = 0; 11 int col = colcnt; 12 13 while (row <= rowcnt && col >= 0) 14 { 15 if (target == array[row][col]) 16 { 17 return true; 18 } 19 else if (target < array[row][col]) 20 { 21 col--; 22 } 23 else 24 { 25 row++; 26 } 27 } 28 return false; 29 } 30 31 return false; 32 } 33 }