[Leetcode]74. Search a 2D Matrix
来源:互联网 发布:致幻蘑菇 知乎 编辑:程序博客网 时间:2024/05/17 11:08
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
- Integers in each row are sorted from left to right.
- The first integer of each row is greater than the last integer of the previous row.
For example,
Consider the following matrix:
[ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50]]
Given target = 3
, return true
.
class Solution {public: bool searchMatrix(vector<vector<int>>& matrix, int target) { 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) { row++; } else col--; } return false; }};
0 0
- LeetCode 74. Search a 2D Matrix
- [LeetCode]74.Search a 2D Matrix
- LeetCode --- 74. Search a 2D Matrix
- [Leetcode] 74. Search a 2D Matrix
- [leetcode] 74.Search a 2D Matrix
- Leetcode 74. Search a 2D Matrix
- [LeetCode]74. Search a 2D Matrix
- 74. Search a 2D Matrix LeetCode
- [LeetCode]74. Search a 2D Matrix
- [LeetCode]74. Search a 2D Matrix
- leetcode 74. Search a 2D Matrix
- LeetCode 74. Search a 2D Matrix
- LeetCode 74. Search a 2D Matrix
- LeetCode *** 74. Search a 2D Matrix
- leetcode 74. Search a 2D Matrix
- LeetCode 74. Search a 2D Matrix
- leetcode-74. Search a 2D Matrix
- [leetcode] 74. Search a 2D Matrix
- golang的参数验证
- [C++]高效使用c++11--理解auto类型推导
- Codeforces700BConnecting Universities(算贡献)
- 2016.7.24 (c++编程思想)
- Excel动态合并行、合并列
- [Leetcode]74. Search a 2D Matrix
- mongodb 使用python作客户端
- HDU 4455 Substrings 第37届ACM/ICPC 杭州赛区现场赛 C题 (DP)
- Python学习笔记16:网络编程
- LeetCode 112. Path Sum
- 正则基础之——贪婪与非贪婪模式
- 利用Fiddler手机抓包对ONE·APP网页爬虫实现电影资讯微信Java开发
- Factorial Trailing Zeroes
- 基于最小二乘法的直线拟合----同济---第六版---下册---125页