AlgoFrames

Longest increasing subsequence

Standard · Write code · about 15 min

Given nums, return the length of the longest strictly increasing subsequence. A subsequence keeps the original order but may skip numbers.

Example 1

Input:

[[10,9,2,5,3,7,101,18]]

Output:

4

One longest run is 2, 3, 7, 101.

Example 2

Input:

[[7,7,7,7,7]]

Output:

1

Equal numbers do not count as increasing.

Constraints

  • 1 ≤ nums.length ≤ 2500
  • −10⁴ ≤ nums[i] ≤ 10⁴

Learn the idea first: Longest increasing subsequence; the n log n version, a visual lesson.

More Longest increasing subsequence; the n log n version problems