213. House Robber II#34
Open
hemispherium wants to merge 2 commits into
Open
Conversation
liquo-rice
reviewed
Apr 23, 2026
|
|
||
| ### step3 | ||
|
|
||
| 3回通すまで書き直し。 |
nodchip
reviewed
Apr 23, 2026
| public: | ||
| int rob(vector<int>& nums) { | ||
| int size = nums.size(); | ||
| vector<vector<int>> sum(size, vector<int>(2)); |
There was a problem hiding this comment.
first~last までの範囲で盗めるお金を最大化する関数を実装し、 0~nums.size()-2 と 1~nums.size()-1 の範囲で、それぞれ盗めるお金の最大値を算出し、 max() を取る実装のほうがシンプルになると思います。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。alternative-solution.cppで実装して追加してみました。
5ky7
reviewed
Apr 23, 2026
Comment on lines
+7
to
+9
| if (i == 0) { | ||
| sum[i][0] = 0; | ||
| sum[i][1] = nums[i]; |
There was a problem hiding this comment.
forループの外に出して,forをi = 1から始める方が見やすいと感じました.
sum[0][0] = 0;
sum[0][0] = nums[0];
for (int i = 1; i < size; ++i) {
Owner
Author
There was a problem hiding this comment.
たしかにこれはfor文の外に出してしまったほうがよさそうですね。ありがとうございます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
この問題:https://leetcode.com/problems/house-robber-ii/description/
次に解く問題:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/