LintCode:最长上升连续子序列

LintCode:最长上升连续子序列

class Solution:
    # @param {int[]} A an array of Integer
    # @return {int}  an integer
    def longestIncreasingContinuousSubsequence(self, A):
        # Write your code here
        if len(A) == 0:
            return 0
        min_num = A[0]
        max_num = A[0]
        r_ans = 1
        r_ans_list = []
        d_ans = 1
        d_ans_list = []
        for i in range(len(A)):
            if A[i] > min_num:
                r_ans += 1
                min_num = A[i]
                r_ans_list.append(r_ans)
            else:
                r_ans_list.append(r_ans)
                r_ans = 1
                min_num = A[i]
            if A[i] < max_num:
                d_ans += 1
                max_num = A[i]
                d_ans_list.append(d_ans)
            else:
                d_ans_list.append(d_ans)
                d_ans = 1
                max_num = A[i]
        return max(r_ans_list + d_ans_list)

你可能感兴趣的:(lintcode,python)