二位数组中的查找

Posted xiaolongren

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二位数组中的查找相关的知识,希望对你有一定的参考价值。

 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     }

 

以上是关于二位数组中的查找的主要内容,如果未能解决你的问题,请参考以下文章

如果找到第一个数组中的特定键,则在第二个数组中查找值

比较两个数组并查找第二个数组中缺少的项目[重复]

php 按照二位数组中某个指定的字段进行排序

在C中将大十进制输入转换为256位数组中的十六进制输出

在python中查找多个组中的最大值

c语言,如何从确定的二位数组中任取其中2元素,才能不重不漏得把所有情况取到?