https://leetcode.com/problems/longest-increasing-subsequence/
Medium
Given an unsorted array of integers, find the length of longest increasing subsequence.
Example:
Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
Note:
- There may be more than one LIS combination, it is only necessary for you to return the length.
- Your algorithm should run in O(n2) complexity.
Follow up: Could you improve it to O(n log n) time complexity?
- 经典DP。
- 第一种解法DP,定义f[ i ]为i位置时最长增长序列长度,f[ i ] = max( f[ j ] + 1 ) if nums[ i ] > nums[ j ]。初始时f[ i ] = 1,目标函数为 max( f[ i ] ),注意不是f[ n ]。
- 第二种解法Patience sorting。
- https://leetcode.com/problems/longest-increasing-subsequence/solution/
- https://leetcode.com/problems/longest-increasing-subsequence/discuss/74824/JavaPython-Binary-search-O(nlogn)-time-with-explanation
- https://en.wikipedia.org/wiki/Patience_sorting
- https://www.cs.princeton.edu/courses/archive/spring13/cos423/lectures/LongestIncreasingSubsequence.pdf