004.二维数组中的查找

# -*- coding:utf-8 -*-
class Solution(object):

    def fNumInSorted(self,input_list,target_num):
        if not input_list:
            return
        if not target_num:
            return
        row = len(input_list)
        col = len(input_list[0])

        i=0
        j=col-1

        while i<row and j >=0:
            if input_list[i][j] > target_num:
                j = j - 1

            elif input_list[i][j] < target_num:
                i = i + 1
            else:
                return  True
        else:
            return False
s = Solution()
list1 = [
    [1,2,8,9],
    [2,4,9,12],
    [4,7,10,13],
    [6,8,11,15]
]
print s.fNumInSorted([],15)

  

原文地址:https://www.cnblogs.com/wanyp/p/10065558.html