[LintCode]28.搜索二维矩阵
来源:互联网 发布:怎样加入淘宝 编辑:程序博客网 时间:2024/05/22 08:29
写出一个高效的算法来搜索 m × n矩阵中的值。
这个矩阵具有以下特性:每行中的整数从左到右是排序的。
每行的第一个数大于上一行的最后一个整数。
样例
考虑下列矩阵:
[ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50]]
给出 target = 3
,返回 true
class Solution {public: /** * @param matrix, a list of lists of integers * @param target, an integer * @return a boolean, indicate whether matrix contains target */ bool searchMatrix(vector<vector<int> > &matrix, int target) { if(matrix.empty() || matrix[0].empty()) { return false; } int row=0; int col=matrix[0].size()-1; while(row<matrix.size() && col>-1){ if(matrix[row][col]==target){ return true; }else if(matrix[row][col] > target){ col--; }else{ row++; } } return false; }};
阅读全文
0 0
- [LintCode]28.搜索二维矩阵
- lintcode ---- 搜索二维矩阵
- lintcode ----搜索二维矩阵
- 【LintCode】搜索二维矩阵
- lintcode,搜索二维矩阵
- LintCode : 搜索二维矩阵
- Lintcode:搜索二维矩阵
- LintCode: 28. 搜索二维矩阵 Java
- LintCode:搜索二维矩阵 II
- LintCode:搜索二维矩阵 II
- 【LintCode】搜索二维矩阵 II
- lintcode,搜索二维矩阵 II
- Lintcode 搜索二维矩阵 II
- LintCode 28 搜索二维矩阵
- lintcode---搜索二维矩阵Ⅱ
- lintcode-搜索二维矩阵II-38
- 搜索二维矩阵——LintCode
- [LintCode]搜索二维矩阵 II
- 论算法性能的重要性
- 欢迎使用CSDN-markdown编辑器
- 不同领域的人们是怎样使用思维导图的(上)
- 数据结构之数组(C语言实现)
- objc[1183]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0
- [LintCode]28.搜索二维矩阵
- 详解大端模式和小端模式
- myCal.get(Calendar.DAY_OF_WEEK)-1是什么意思?
- 机器学习(3)——监督学习
- 微信公众号---自定义菜单创建接口---创建一级菜单
- 转储分析之寻找SDK安装程序挂死原因视频 笔记整理
- Navicat Premium实现mysql数据库备份/还原
- MySQL 数据库权限简单管理
- 一个错误使用Android 属性动画的例子