We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 513c17e commit f2ac985Copy full SHA for f2ac985
longest_increasing_subsequence.py
@@ -0,0 +1,21 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+class Solution:
4
+ """
5
+ @param nums: The integer array
6
+ @return: The length of LIS (longest increasing subsequence)
7
8
+ def longestIncreasingSubsequence(self, nums):
9
+ # write your code here
10
+ ret = 0
11
+ if nums:
12
+ caches = [0] * len(nums) # 到当前位置最长子序列长度
13
+ caches[0] = 1
14
+ for i in xrange(1, len(nums)):
15
+ _len = 0
16
+ for j in xrange(i):
17
+ if nums[j] < nums[i]:
18
+ _len = max(caches[j], _len)
19
+ caches[i] = _len + 1
20
+ ret = max(caches[i], ret)
21
+ return ret
0 commit comments