Skip to content

Longest Increasing Subsequence

LeetCode

01 · Question

Given an integer array nums, return the length of the longest strictly increasing subsequence.

02 · Solution

Reference solution

1def lengthOfLIS(nums: List[int]) -> int:
2 n = len(nums)
3 dp = [1] * n
4
5 for i in range(n):
6 for j in range(i):
7 if nums[j] < nums[i]:
8 dp[i] = max(dp[i], dp[j] + 1)
9
10 return max(dp)