题解 | #二维数组中的查找#

二维数组中的查找

https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e

# move the location from the top right or bottom left and move one step a time
class Solution:
    def Find(self , target: int, array: List[List[int]]) -> bool:
        # write code here
        m = len(array)
        n = len(array[0])
        irow, icol = 0, n - 1
        while irow <= m - 1 and icol >= 0:
            cur_val = array[irow][icol]
            if cur_val == target:
                return True
            elif cur_val > target:
                icol -= 1
            else:
                irow += 1
        return False

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务