Longest Increasing Subsequence
Problem statement
Given an integer array nums, find its longest strictly increasing subsequence. A subsequence keeps the original order but may skip elements.
For this exercise, assume you return the length of that subsequence. Equal values do not extend it, and an empty array has answer 0.
Function
lengthOfLIS(nums: int[]) → intExamples
Example 1
nums = [10,9,2,5,3,7,101,18]return = 4The values [2,3,7,18] form a strictly increasing subsequence of length 4. No subsequence of length 5 exists.
Example 2
nums = [2,2,2]return = 1Any single value forms an increasing subsequence. Equal values cannot extend it, so the answer is 1.
Constraints
0 <= nums.length <= 20000-10^9 <= nums[i] <= 10^9