题解 | #最长递增子序列#
最长递增子序列
http://www.nowcoder.com/practice/9cf027bf54714ad889d4f30ff0ae5481
Python 超时
class Solution: def LIS(self, arr): # write code here length = len(arr) if len(arr) < 1: return [] dp = [[a] for a in arr] ans = [] for i in range(length): for j in range(i): if arr[i] > arr[j]: if len(dp[j]) + 1 >= len(dp[i]): dp[i] = dp[j] + [arr[i]] res = dp[0] print(dp) for i in range(1, length): if len(dp[i]) > len(res): res = dp[i] return res