一个方法团灭 LeetCode 打家劫舍问题 :: labuladong的算法小抄 #1075
Replies: 14 comments 2 replies
-
学到了!! |
Beta Was this translation helpful? Give feedback.
-
学到了 |
Beta Was this translation helpful? Give feedback.
-
感谢东哥分享的文章,层次鲜明,难度递进,学到了很多东西。 |
Beta Was this translation helpful? Give feedback.
-
滴滴滴打卡 |
Beta Was this translation helpful? Give feedback.
-
打家劫舍1 这个自顶向下的dp也不错的,也好理解,比递归简单点。 |
Beta Was this translation helpful? Give feedback.
-
抢房子 |
Beta Was this translation helpful? Give feedback.
-
最后一个tree的很有启发性,对于tree structure,可以直接通过天然的recursion来保证每个node只计算一次,并且每个node 记录抢或不抢的二元组也很聪明,学习了 |
Beta Was this translation helpful? Give feedback.
-
20221229 打卡 |
Beta Was this translation helpful? Give feedback.
-
第三道题的两种解法都很巧妙,可以加深对重叠子问题的理解,获益匪浅 |
Beta Was this translation helpful? Give feedback.
-
为什么house robber的dp[i]定义是从该位置start的最大值,而LIS是在该位置结束的最大值呢~ 我能理解为什么这样是行得通的,但在找思路的时候自己就想不到这个解法 |
Beta Was this translation helpful? Give feedback.
-
感谢东哥! 来一个打家劫舍III的 Swift版本: |
Beta Was this translation helpful? Give feedback.
-
第三题来个c++版 int rob(TreeNode* root) {
auto ans = rob_aux(root);
return max(ans.first, ans.second);
}
pair<int, int> rob_aux(TreeNode* root){
if(root == nullptr) return {0, 0};
auto le = rob_aux(root->left), ri = rob_aux(root->right);
return {root->val + le.second + ri.second, max(le.first, le.second) + max(ri.first, ri.second)};
} |
Beta Was this translation helpful? Give feedback.
-
打卡 |
Beta Was this translation helpful? Give feedback.
-
抢房子 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
文章链接点这里:一个方法团灭 LeetCode 打家劫舍问题
评论礼仪 见这里,违者直接拉黑。
Beta Was this translation helpful? Give feedback.
All reactions