力扣刷题Day 69:搜索二维矩阵(74) - 教程

1.题目描述

2.思路

起初判断target是否有可能在矩阵的某一行里,没可能直接返回False,有可能就在这一行里二分查找

3.代码(Python3)

class Solution:    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:        m, n = len(matrix), len(matrix[0])        target_row = -1        for i in range(m):            if target  target: right = mid - 1                else: left = mid + 1        return False

4.执行情况

5.感想

最近做题手挺顺的,也可能是因为题目简单吧。

posted @ 2025-07-22 12:06  yfceshi  阅读(6)  评论(0)    收藏  举报