forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0300.py
More file actions
27 lines (24 loc) · 706 Bytes
/
0300.py
File metadata and controls
27 lines (24 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def lengthOfLIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
mem = list()
len_nums = len(nums)
for i in range(len_nums):
low, upper = 0, len(mem)
while low < upper:
mid = (upper - low)//2 + low
if mem[mid] < nums[i]:
low = mid + 1
else:
upper = mid
if upper == len(mem):
mem.append(nums[i])
else:
mem[upper] = nums[i]
return len(mem)
if __name__ == '__main__':
nums = [10,9,2,5,3,7,101,18]
print(Solution().lengthOfLIS(nums))