mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-31 19:13:42 +00:00
Update Leetcode 题解 - 动态规划.md
精简最长递增子序列中求最大值的说明。
This commit is contained in:
@@ -579,16 +579,6 @@ public int lengthOfLIS(int[] nums) {
|
||||
}
|
||||
```
|
||||
|
||||
使用 Stream 求最大值会导致运行时间过长,可以改成以下形式:
|
||||
|
||||
```java
|
||||
int ret = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
ret = Math.max(ret, dp[i]);
|
||||
}
|
||||
return ret;
|
||||
```
|
||||
|
||||
以上解法的时间复杂度为 O(N<sup>2</sup>),可以使用二分查找将时间复杂度降低为 O(NlogN)。
|
||||
|
||||
定义一个 tails 数组,其中 tails[i] 存储所有长度为 i + 1 的递增子序列中最小的末尾元素。对于一个元素 x,
|
||||
|
||||
Reference in New Issue
Block a user