# Middle-题目32：240. Search a 2D Matrix II

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 in ascending from left to right.
Integers in each column are sorted in ascending from top to bottom.
For example,
[
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]

public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
if(matrix.length==0)
return false;
int rows=matrix.length,cols=matrix[0].length;
int i=0,j=cols-1;
while(j>=0 && i<=rows-1) {
if(matrix[i][j] == target)
return true;
else if(matrix[i][j] < target)
i++;
else
j--;
}
return false;
}
}

13ms,beats 56.57%,众数13ms,37.38%
Cmershen的碎碎念：

#### [Leetcode] 562. Longest Line of Consecutive One in Matrix 解题报告

2017-12-24 09:41:22

#### 算法经典面试题整理（java实现）

2015-06-11 19:23:20

#### [LeetCode]189.Rotate Array

2015-02-25 22:27:55

#### leetcode - Search a 2D Matrix II

2015-07-25 13:52:56

#### 【LeetCode-面试算法经典-Java实现】【074-Search a 2D Matrix（搜索二维矩阵）】

2015-07-30 06:34:39

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

2015-07-23 06:07:35

#### Leetcode 240 Search a 2D Matrix II （二分法和分治法解决有序二维数组查找）

2015-07-23 20:41:07

#### LeetCode 240： Search a 2D Matrix II

2015-07-30 19:07:55

#### leetcode解题报告：240. Search a 2D Matrix II

2016-09-12 19:25:51

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

2014-04-21 02:29:21