Skip to content

Commit 5eaf1da

Browse files
authored
上升子序列
找到第一个比x大的,更新那个值,记录更小的tail Reference: (Leetcode 300)(https://leetcode.com/problems/longest-increasing-subsequence/discuss/74824/JavaPython-Binary-search-O(nlogn)-time-with-explanation)
1 parent e89b0aa commit 5eaf1da

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

notes/Leetcode 题解.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,7 @@ return ret;
27812781
定义一个 tails 数组,其中 tails[i] 存储长度为 i + 1 的最长递增子序列的最后一个元素。对于一个元素 x,
27822782

27832783
- 如果它大于 tails 数组所有的值,那么把它添加到 tails 后面,表示最长递增子序列长度加 1;
2784-
- 如果 tails[i-1] < x <= tails[i],那么更新 tails[i-1] = x。
2784+
- 如果 tails[i-1] < x <= tails[i],那么更新 tails[i] = x。
27852785

27862786
例如对于数组 [4,3,6,5],有:
27872787

0 commit comments

Comments
 (0)