###### 【Leet Code】74. Search a 2D Matrix---Medium

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) {
if(matrix.size() < 1 || matrix[0].size() < 1) return false;
int up = 0, down = matrix.size()-1;
int mid = 0;
while(up <= down)
{
mid = (up + down)/2;
if(searchArray(matrix[mid], target)) return true;

if(target < matrix[mid][0]) down = mid -1;
else up = mid + 1;
}
return false;
}
private:
bool searchArray(vector<int>& nums, int target){
int left = 0, right = nums.size() -1;
int mid = 0;
while(left <= right)
{
mid = (left + right)/2;
if(target == nums[mid])
return true;
if(target > nums[mid])
left = mid + 1;
else right = mid - 1;
}
return false;
}

};

#### LeetCode74——Search a 2D Matrix

2015-11-14 14:27:29

#### 【LEETCODE】74-Search a 2D Matrix [Python]

2016-01-07 16:04:59

#### 74 Search a 2D Matrix

2015-10-22 20:36:35

#### LeetCode 74:Search a 2D Matrix

2016-01-20 21:49:29

#### leetCode 74.Search a 2D Matrix(搜索二维矩阵) 解题思路和方法

2015-07-19 16:35:54

#### 【leetcode】74. Search a 2D Matrix【java】

2016-12-20 16:56:50

#### leetcode 240: Search a 2D Matrix II

2015-07-23 06:07:35

#### Search a 2D Matrix -- LeetCode

2014-04-21 02:29:21

#### 【LeetCode】Word Search II 解题报告

2015-05-19 16:52:33

#### LeetCode | Search a 2D Matrix

2013-12-11 11:57:34

## 不良信息举报

【Leet Code】74. Search a 2D Matrix---Medium