首页 > 其他 > 详细

240 Search a 2D Matrix II

时间:2015-07-24 06:54:00      阅读:266      评论:0      收藏:0      [点我收藏+]

240 Search a 2D Matrix II 

这是个young‘s矩阵,最好的就是O(m+n)的算法了

class Solution:
    # @param {integer[][]} matrix
    # @param {integer} target
    # @return {boolean}
    def searchMatrix(self, matrix, target):
        m = len(martix)
        if m == 0:
            return False
        n = len(matrix[0])
        i, j = m - 1, 0
        while i >= 0 and j < n:
            if matrix[i][j] == target:
                return True
            elif matrix[i][j] < target:
                j += 1
            else:
                i -= 1
        return False

 

240 Search a 2D Matrix II

原文:http://www.cnblogs.com/dapanshe/p/4672300.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!