3、二维数组中的查找
来源:互联网 发布:python 伪装成浏览器 编辑:程序博客网 时间:2024/06/05 20:30
数组的条件:从上至下和从左至右都是递增的
class Program { static void Main(string[] args) { int[,] nums = { { 1, 2, 8, 9 }, { 2, 4, 9, 12 }, { 4, 7, 10, 13 }, { 6, 8, 11, 15 } }; Console.WriteLine(Find(nums, nums.GetLength(0), nums.GetLength(1), 8)); Console.ReadKey(); } static bool Find(int[,] nums, int rows, int colomns, int target) { bool isFind = false; if (rows > 0 && colomns > 0) { // row,column 就代表下标了 int row = 0; int column = colomns - 1; while (row < rows && column < colomns) { if (nums[row, column] == target) { isFind = true; return isFind; } else if (nums[row, column] < target) { ++row; } else if (nums[row, column] > target) { --column; } } } return false; }
阅读全文
0 0
- 二维数组中的查找3
- 3、二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 数据结构与算法(Java描述)-8、中缀表达式转换后缀表达式算法
- 六级_第十一天
- 如何在通信行业中获得好排名,就上VoIP通信技术网
- 500. Keyboard Row
- 泛型
- 3、二维数组中的查找
- 构建高性能web之路------mysql读写分离实战
- Java基础总结
- AngularJS
- 数据结构入门---初始二叉树(下)
- offer412--序列和为s
- 1.4-温度转换程序实例
- Windows下Mongodb安装及配置
- 优秀开源项目