mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
Merge branch 'youngyangyang04:master' into leetcode-add-complexity-analysis-hashtable
This commit is contained in:
@ -128,12 +128,12 @@ Java:
|
||||
class Solution {
|
||||
public int climbStairs(int n) {
|
||||
int[] dp = new int[n + 1];
|
||||
int[] weight = {1,2};
|
||||
int m = 2;
|
||||
dp[0] = 1;
|
||||
|
||||
for (int i = 0; i <= n; i++) {
|
||||
for (int j = 0; j < weight.length; j++) {
|
||||
if (i >= weight[j]) dp[i] += dp[i - weight[j]];
|
||||
for (int i = 1; i <= n; i++) { // 遍历背包
|
||||
for (int j = 1; j <= m; j++) { //遍历物品
|
||||
if (i >= j) dp[i] += dp[i - j];
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,3 +227,4 @@ function climbStairs(n: number): number {
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
@ -133,6 +133,11 @@ public:
|
||||
LinkedNode* tmp = cur->next;
|
||||
cur->next = cur->next->next;
|
||||
delete tmp;
|
||||
//delete命令指示释放了tmp指针原本所指的那部分内存,
|
||||
//被delete后的指针tmp的值(地址)并非就是NULL,而是随机值。也就是被delete后,
|
||||
//如果不再加上一句tmp=nullptr,tmp会成为乱指的野指针
|
||||
//如果之后的程序不小心使用了tmp,会指向难以预想的内存空间
|
||||
tmp=nullptr;
|
||||
_size--;
|
||||
}
|
||||
|
||||
@ -1450,3 +1455,4 @@ impl MyLinkedList {
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
Reference in New Issue
Block a user