Java实现-搜索二维矩阵
来源:互联网 发布:2016超级女声网络投票 编辑:程序博客网 时间:2024/06/03 12:14
写出一个高效的算法来搜索 m × n矩阵中的值。
这个矩阵具有以下特性:
- 每行中的整数从左到右是排序的。
- 每行的第一个数大于上一行的最后一个整数。
样例
考虑下列矩阵:
[ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50]]
给出 target = 3
,返回 true
public class Solution { /** * @param matrix, a list of lists of integers * @param target, an integer * @return a boolean, indicate whether matrix contains target */ public boolean searchMatrix(int[][] matrix, int target) { if(matrix==null||matrix.length==0){return false;}int row=matrix.length;int column=matrix[0].length;for(int i=0;i<row;i++){for(int j=column-1;j>=0;j--){if(matrix[i][j]==target){return true;}else if(matrix[i][j]>target){continue;}else{break;}}}return false; }}
阅读全文
0 0
- Java实现-搜索二维矩阵
- Java实现-搜索二维矩阵II
- LintCode: 28. 搜索二维矩阵 Java
- 【LeetCode-面试算法经典-Java实现】【074-Search a 2D Matrix(搜索二维矩阵)】
- 题目:搜索二维矩阵
- 搜索二维矩阵 II
- 搜索二维矩阵 II
- 搜索二维矩阵
- 搜索二维矩阵 II
- 搜索二维矩阵
- lintcode ---- 搜索二维矩阵
- lintcode ----搜索二维矩阵
- 搜索二维矩阵II
- 【LintCode】搜索二维矩阵
- 搜索二维矩阵
- lintcode,搜索二维矩阵
- 搜索二维矩阵
- 搜索二维矩阵 II
- 支持手势缩放的ImageView
- 剑指offer面试题[30]-最小的k个数
- 典型递归问题整理
- lucene 3(相关度排序)
- Android禁止ViewPager的左右滑动
- Java实现-搜索二维矩阵
- java 泛型
- 并发(二):理解volatile
- Android 用MediaCodec实现视频硬解码
- QAbstractSocket::waitForDisconnected() is not allowed in UnconnectedState
- 对于职业、软件学习的感想
- Hdu 2089 不要62
- 大型web系统数据缓存设计
- 设计模式(一)-策略模式