Skip to main content

300. Longest Increasing Subsequence

from typing import List


class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
if len(nums) == 0:
return 0
memo = [1] * len(nums)
for i in range(len(nums)):
for j in range(i):
if nums[i] > nums[j]:
memo[i] = max(memo[i], 1 + memo[j])
return max(memo)


s = Solution()
print(s.lengthOfLIS([10, 9, 2, 5, 3, 7, 101, 18]))