Skip to content

Commit 55add41

Browse files
authored
Create Longest Increasing Subsequence - Leetcode 300.py
1 parent 9d26391 commit 55add41

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def lengthOfLIS(self, nums: List[int]) -> int:
3+
# Bottom Up DP (Tabulation)
4+
# Time: O(n^2)
5+
# Space: O(n)
6+
7+
n = len(nums)
8+
dp = [1] * n
9+
10+
for i in range(1, n):
11+
for j in range(i):
12+
if nums[i] > nums[j]:
13+
dp[i] = max(dp[i], dp[j] + 1)
14+
15+
return max(dp)

0 commit comments

Comments
 (0)