def incSeq(seq):
    start = 0
    for i in xrange(1, len(seq)):
        if seq[i] < seq[i-1]:
            yield start, i - start
            start = i
maxIncSeq = reduce(lambda x,y: x if x[1]>y[1] else y, incSeq(seq))

得到最长递增子串长度及起始位置,时间复杂度O(n).

posted on 2013-10-22 10:52  andy071001  阅读(255)  评论(0编辑  收藏  举报