From dee1affc3b63f3925eb094b7f88f7fd84cb9d008 Mon Sep 17 00:00:00 2001 From: xqm32 <458173774@qq.com> Date: Fri, 4 Aug 2023 22:30:17 +0800 Subject: [PATCH] leetcode: finished #74 --- content/leetcode/2023/8.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/content/leetcode/2023/8.md b/content/leetcode/2023/8.md index bd14d5b08..167b5d522 100644 --- a/content/leetcode/2023/8.md +++ b/content/leetcode/2023/8.md @@ -3,6 +3,37 @@ title: "2023.8" draft: false --- +# 2023.8.4 + +```python +# +# @lc app=leetcode.cn id=74 lang=python3 +# +# [74] 搜索二维矩阵 +# + +# @lc code=start +from typing import List + + +class Solution: + def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: + if not matrix or not matrix[0]: + return False + row, col = 0, len(matrix[0]) - 1 + while row <= len(matrix) - 1 and col >= 0: + if matrix[row][col] > target: + col -= 1 + elif matrix[row][col] < target: + row += 1 + elif matrix[row][col] == target: + return True + return False + + +# @lc code=end +``` + # 2023.8.3 ```python