LeetCode 240. Search a 2D Matrix II
来源:互联网 发布:jsp无法import java类 编辑:程序博客网 时间:2024/06/12 22:57
原题地址
题目内容
题目分析
这个矩阵从左到右逐渐增大,从上到下也是逐渐增大的。先从最右列第一个数开始比较,如果target大于它,说明target在这一列,否则往左查找,比较左边一列第一个数,以此类推。 确定列数后开始向下寻找行数即可,如果找不到则返回结果fasle。
代码实现
class Solution {public: bool searchMatrix(vector<vector<int>>& matrix, int target) { if(matrix.size() == 0){ return false; } int row = matrix.size(); int col = matrix[0].size(); int i = 0,j = col-1; while(i < row && j >= 0){ if(matrix[i][j] == target) return true; else if(matrix[i][j] > target){ j--; }else i++; } return false; }};
阅读全文
0 0
- #leetcode#Search a 2D Matrix II
- [LeetCode] Search a 2D Matrix II
- leetcode: Search a 2D Matrix II
- leetcode - Search a 2D Matrix II
- [leetcode] Search a 2D Matrix II
- 【leetcode】Search a 2D Matrix II
- Leetcode: Search a 2D Matrix II
- LeetCode Search a 2D Matrix II
- [Leetcode]Search a 2D Matrix II
- [LeetCode]Search a 2D Matrix II
- LeetCode Search a 2D Matrix II
- [LeetCode]Search a 2D Matrix II
- LeetCode || Search a 2D Matrix II
- LeetCode----Search a 2D Matrix II
- Leetcode: Search a 2D Matrix II
- *LeetCode-Search a 2D Matrix II
- Search a 2D Matrix II -- leetcode
- leetcode | Search a 2D Matrix II
- 1016. 部分A+B (15)
- 关于复合字面量的使用问题
- 五、Spring Cloud 的 Hystrix 组件
- Java 聊天室的简单实现原理
- Eclipse一直building workspace问题解决归纳
- LeetCode 240. Search a 2D Matrix II
- 新手win10 安装ubuntu双系统
- 关于hash表(散列表)的简单整理
- 1015. 德才论 (25)
- java基于poi的excel表格处理(自定义注解、针对List与enum进行处理)
- android 原生工程中集成第三方so动态库和.a静态库和apk
- 程序员必备的几个图形制作工具
- 好玩的Python库tqdm
- leetcode编程记录1 #8 String to Integer (atoi)