笔记 二维数组中的查找
来源:互联网 发布:photoshop盖印图层 mac 编辑:程序博客网 时间:2024/05/22 03:47
总结
从右上角开始判定,可以一次排除一列或者一行的数据右上角的坐标是row=0,column=columns-1,如果大于Number,说明在左边,column-1,如果小于Number,说明在下面,row+1
package findInMatrix;public class FindInMatrix { public static void main(String[] args) { // TODO Auto-generated method stub test1(); test2(); } static void test1() { int matrix[][] = { { 1, 2, 8, 9 }, { 2, 4, 9, 12 }, { 4, 7, 10, 13 }, { 6, 8, 11, 15 } }; System.out.println(find(matrix, 1)); } static void test2() { System.out.println(find(null, 7)); } static boolean find(int[][] matrix, int number) { boolean found = false; if (matrix != null) { int rows = matrix.length; int columns = matrix[0].length; int row = 0; int column = columns - 1; while (row < rows && column >= 0) { if (matrix[row][column] == number) { found = true; break; } else if (matrix[row][column] > number) { --column; } else { ++row; } } } return found; }}
0 0
- 笔记 二维数组中的查找
- 【笔记】二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 二维数组中的查找
- 比较字符串s1和s2,若s1>s2,输出一个正数,若s1=s2,输出0,若s1<s2,输出一个负数。不用strcpy函数
- Go语言知识积累:windows开发环境搭建
- PDH错误代码
- 2009-2010年中国商业智能市场分析报告
- 将字符数组s2中全部字符复制到字符数组s1,不用strcpy(复制时‘\0’也要复制过去‘\0’后面的字符不用复制)
- 笔记 二维数组中的查找
- Android Service 之三(Bind Service, 继承自 Binder 类)
- 工作总结第十五天
- 基于ViewPager的自动轮播模块–解决与ScrollView冲突问题
- java线程同步
- 删除链表中和某一个数相同的元素(单向链表)哈理工oj1546
- 线性表逆置
- Single Number
- cinder 之driver 的实现