Skip to content

Commit

Permalink
Update 01.Linear-DP-01.md
Browse files Browse the repository at this point in the history
correct typo of linear dp
应该是nums[j]>=nums[i]
  • Loading branch information
wangxinalex authored Jul 3, 2024
1 parent 381b4c8 commit e6237f7
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

- 如果 $nums[j] < nums[i]$,则 $nums[i]$ 可以接在 $nums[j]$ 后面,此时以 $nums[i]$ 结尾的最长递增子序列长度会在「以 $nums[j]$ 结尾的最长递增子序列长度」的基础上加 $1$,即:$dp[i] = dp[j] + 1$。

- 如果 $nums[j] \le nums[i]$,则 $nums[i]$ 不可以接在 $nums[j]$ 后面,可以直接跳过。
- 如果 $nums[j] \ge nums[i]$,则 $nums[i]$ 不可以接在 $nums[j]$ 后面,可以直接跳过。

综上,我们的状态转移方程为:$dp[i] = max(dp[i], dp[j] + 1), 0 \le j < i, nums[j] < nums[i]$。

Expand Down

0 comments on commit e6237f7

Please sign in to comment.