longest increasing sub-sequence

Go Here

直接上代码,关键还是python的写法太简洁了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import bisect
class :
def lengthOfLIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
dp = []
for n in nums:
pos = bisect.bisect_left(dp, n)

if pos == len(dp):
dp.append(n)
else:
dp[pos] = n
return len(dp)