📘
Longest Increasing Subsequence
MediumDynamic Programming
Given an integer array nums, return the length of the longest strictly increasing subsequence.
A subsequence is derived from the array by deleting some or no elements without changing the order of the remaining elements.
Example:
Input:
10,9,2,5,3,7,101,18
Output:
4
Reasoning:
- The input array is
10, 9, 2, 5, 3, 7, 101, 18, and we need to find the longest strictly increasing subsequence. - We can start by identifying potential increasing subsequences, such as
2, 5, 7, 101or2, 3, 7, 101or2, 5, 7, 18. - The longest increasing subsequence in the array is
2, 5, 7, 101or2, 3, 7, 101with a length of 4. - The final output is the length of the longest increasing subsequence, which is 4.
Constraints:
- 1 <= len(nums) <= 2500
- -10^4 <= nums[i] <= 10^4
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.