# 搜索二维矩阵

<p>编写一个高效的算法来判断 <code>m x n</code> 矩阵中，是否存在一个目标值。该矩阵具有如下特性：</p><ul>	<li>每行中的整数从左到右按升序排列。</li>	<li>每行的第一个整数大于前一行的最后一个整数。</li></ul><p> </p><p><strong>示例 1：</strong></p><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0074.Search%20a%202D%20Matrix/images/mat.jpg" style="width: 322px; height: 242px;" /><pre><strong>输入：</strong>matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3<strong><br />输出：</strong>true</pre><p><strong>示例 2：</strong></p><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0074.Search%20a%202D%20Matrix/images/mat2.jpg" style="width: 322px; height: 242px;" /><pre><strong>输入：</strong>matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13<strong><br />输出：</strong>false</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>m == matrix.length</code></li>	<li><code>n == matrix[i].length</code></li>	<li><code>1 <= m, n <= 100</code></li>	<li><code>-10<sup>4</sup> <= matrix[i][j], target <= 10<sup>4</sup></code></li></ul>

## template

```python
class Solution(object):
	def searchMatrix(self, matrix, target):
		"""
		:type matrix: List[List[int]]
		:type target: int
		:rtype: bool
		"""
		if not matrix or not matrix[0]:
			return False
		rows = len(matrix)
		cols = len(matrix[0])
		row, col = 0, cols - 1
		while True:
			if row < rows and col >= 0:
				if matrix[row][col] == target:
					return True
				elif matrix[row][col] < target:
					row += 1
				else:
					col -= 1
			else:
				return False
# %%
s = Solution()
print(s.searchMatrix(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```