天天看点

牛客网编程题——二维双向递增数组找目标值

牛客网编程题——二维双向递增数组找目标值
# -*- coding:utf-8 -*-
class Solution:
    # array 二维列表
    def Find(self, target, array):
        # write code here
        rows = len(array)
        cols = len(array[0])
        startx = rows - 1
        starty = 0
        while startx >= 0 and starty <= cols - 1:
            if target == array[startx][starty]:
                return True
            elif array[startx][starty] > target:
                startx -= 1
            elif array[startx][starty] < target:
                starty += 1
        return False