Skip to content

198. House Robber#33

Open
5103246 wants to merge 1 commit intomainfrom
198-house-robber
Open

198. House Robber#33
5103246 wants to merge 1 commit intomainfrom
198-house-robber

Conversation

@5103246
Copy link
Copy Markdown
Owner

@5103246 5103246 commented Nov 14, 2025

if (nums.size() == 1) {
return nums[0];
}
vector<int> sums(nums.size());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

読み手にとって読みやすくするため、処理の区切りを視覚的に分かりやすくする目的で、適宜空行を入れることをおすすめします。

参考までにスタイルガイドへのリンクを貼ります。

Use vertical whitespace sparingly; unnecessary blank lines make it harder to see overall code structure. Use blank lines only where they aid the reader in understanding the structure.

https://google.github.io/styleguide/cppguide.html#Vertical_Whitespace

上記のスタイルガイドは唯一絶対のルールではなく、複数あるスタイルガイドの一つに過ぎないということを念頭に置くことをお勧めします。また、所属するチームにより何が良いとされているかは変わります。自分の中で良い書き方の基準を持ちつつ、チームの平均的な書き方で書くことをお勧めいたします。


- 書いてみた感じ、やはりstep1の方が素直でわかりやすく感じたのでstep3ではそれで書く。

## Step3
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step1.3綺麗で読みやすいと思いました。

Comment on lines +142 to +144
int current_total = max_money_without_last + num;
max_money_without_last = max(max_money_without_last, max_money_with_last);
max_money_with_last = current_total;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

良い更新順序だと思います。

for (auto num : nums) {
int current_max = max(max_money_with_last, max_money_without_last + num);
max_money_without_last = max_money_with_last;
max_money_with_last = current_max;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with_lastだとlastに対応する要素を含むもので最大のもの,という誤認をしそうなのでby_lastmax_money_previousなどはいかがでしょうか.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants