二維數組的查找

class Solution:
    def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -> bool:
        if matrix:
            column, row = len(matrix[0]) - 1, 0 
            while column >= 0  and row <  len(matrix) :
                if matrix[row][column] < target:
                    row += 1 
                elif matrix[row][column] > target:
                    column -= 1 
                else:
                    return True
            return False 
        return False 

https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/submissions/

發佈了16 篇原創文章 · 獲贊 6 · 訪問量 5718
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章