标签:mat lis turn 矩阵 ima alt elf while span
题目描述:
方法一:二分
class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: m = len(matrix) if m==0: return False n = len(matrix[0]) left,right = 0,m*n-1 while left<=right: mid_idx = (left+right)//2 mid_element = matrix[mid_idx//n][mid_idx%n] if target == mid_element: return True else: if target<mid_element: right = mid_idx - 1 else: left = mid_idx + 1 return False
标签:mat lis turn 矩阵 ima alt elf while span
原文地址:https://www.cnblogs.com/oldby/p/11178406.html