Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 15c34a2

Browse files
Merge pull request youngyangyang04#2846 from Poivre-hxx/master
fix: 70 爬楼梯删去复杂度的内联公式符
2 parents 7fdb784 + bd1bca9 commit 15c34a2

File tree

2 files changed

+6
-39
lines changed

2 files changed

+6
-39
lines changed

‎problems/0070.爬楼梯.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public:
130130
};
131131
```
132132
133-
* 时间复杂度:$O(n)$
134-
* 空间复杂度:$O(n)$
133+
* 时间复杂度:O(n)
134+
* 空间复杂度:O(n)
135135
136136
当然依然也可以,优化一下空间复杂度,代码如下:
137137
@@ -154,8 +154,8 @@ public:
154154
};
155155
```
156156

157-
* 时间复杂度:$O(n)$
158-
* 空间复杂度:$O(1)$
157+
* 时间复杂度:O(n)
158+
* 空间复杂度:O(1)
159159

160160
后面将讲解的很多动规的题目其实都是当前状态依赖前两个,或者前三个状态,都可以做空间上的优化,**但我个人认为面试中能写出版本一就够了哈,清晰明了,如果面试官要求进一步优化空间的话,我们再去优化**
161161

@@ -524,3 +524,4 @@ impl Solution {
524524
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
525525
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
526526
</a>
527+

‎problems/0518.零钱兑换II.md‎

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ object Solution {
546546
}
547547
}
548548
```
549-
## C
549+
### C
550550

551551
```c
552552
int change(int amount, int* coins, int coinsSize) {
@@ -593,37 +593,3 @@ public class Solution
593593
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
594594
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
595595
</a>
596-
597-
----------
598-
599-
600-
601-
回归本题,动规五步曲来分析如下:
602-
603-
1. 确定dp数组以及下标的含义
604-
605-
dp[j]:凑成总金额j的货币组合数为dp[j]
606-
607-
2. 确定递推公式
608-
609-
dp[j] 就是所有的dp[j - coins[i]](考虑coins[i]的情况)相加。
610-
611-
所以递推公式:dp[j] += dp[j - coins[i]];
612-
613-
**这个递推公式大家应该不陌生了,我在讲解01背包题目的时候在这篇[494. 目标和](https://programmercarl.com/0494.目标和.html)中就讲解了,求装满背包有几种方法,公式都是:dp[j] += dp[j - nums[i]];**
614-
615-
3. dp数组如何初始化
616-
617-
首先dp[0]一定要为1,dp[0] = 1是 递归公式的基础。如果dp[0] = 0 的话,后面所有推导出来的值都是0了。
618-
619-
那么 dp[0] = 1 有没有含义,其实既可以说 凑成总金额0的货币组合数为1,也可以说 凑成总金额0的货币组合数为0,好像都没有毛病。
620-
621-
但题目描述中,也没明确说 amount = 0 的情况,结果应该是多少。
622-
623-
这里我认为题目描述还是要说明一下,因为后台测试数据是默认,amount = 0 的情况,组合数为1的。
624-
625-
下标非0的dp[j]初始化为0,这样累计加dp[j - coins[i]]的时候才不会影响真正的dp[j]
626-
627-
dp[0]=1还说明了一种情况:如果正好选了coins[i]后,也就是j-coins[i] == 0的情况表示这个硬币刚好能选,此时dp[0]为1表示只选coins[i]存在这样的一种选法。
628-
629-
----------------

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /