天天看點

牛客網程式設計題——二維雙向遞增數組找目标值

牛客網程式設計題——二維雙向遞增數組找目标值
# -*- 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