LintCode Q397 Longest Increasing Continuous Subsequence in Python

  • Jinhai ZHOU
  • 2 Minutes
  • 2017年2月8日
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
return max(self.getLongest(A), self.getLongest(list(reversed(A))))
def getLongest(self, A):
count = 0
count_max = 0
for i in xrange(1, len(A)):
if A[i] >= A[i - 1]:
count += 1
else:
count_max = max(count_max, count)
count = 0
return max(count_max, count) + 1
知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。