Skip to content

Commit 7755edf

Browse files
author
He Hao
committed
add nlogn solution to LIS
1 parent ada841c commit 7755edf

File tree

1 file changed

+22
-8
lines changed
  • leetcode_python_solutions

1 file changed

+22
-8
lines changed

leetcode_python_solutions/300.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
class Solution:
2+
"""
3+
Longest Increasing Subsequence
4+
5+
dp[i] denotes the length of the LIS ends with nums[i]
6+
7+
dp[i] = max(dp[i], 1 + dp[j]) for j < i if dp[i] > dp[j]
8+
9+
10+
"""
211
def lengthOfLIS(self, nums: List[int]) -> int:
312
n = len(nums)
413
dp = [1]*n
@@ -8,12 +17,17 @@ def lengthOfLIS(self, nums: List[int]) -> int:
817
dp[i] = max(dp[i], 1+dp[j])
918
return max(dp)
1019

11-
"""
12-
Longest Increasing Subsequence
13-
14-
dp[i] denotes the length of the LIS from nums[0:i+1]
15-
16-
dp[i] = max(1 + dp[j]) for j < i if dp[i] > dp[j]
17-
1820

19-
"""
21+
# import bisect
22+
#
23+
# class Solution:
24+
# def lengthOfLIS(self, nums: List[int]) -> int:
25+
# # dp[i] is the smallest ending number of the LISs with length i+1
26+
# dp = []
27+
# for num in nums:
28+
# index = bisect.bisect_left(dp, num)
29+
# if index == len(dp):
30+
# dp.append(num)
31+
# else:
32+
# dp[index] = num
33+
# return len(dp)

0 commit comments

Comments
 (0)