Skip to content

213. House Robber II #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

213. House Robber II #37

wants to merge 1 commit into from

Conversation

fhiyo
Copy link
Owner

@fhiyo fhiyo commented Jul 7, 2024

Copy link

@hayashi-ay hayashi-ay left a comment

Choose a reason for hiding this comment

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

House Robberの方でしたコメント以外は特にないかなと思います

Comment on lines +110 to +112
prev = max_money_so_far[1]
max_money_so_far[1] = max(max_money_so_far[1], max_money_so_far[0] + nums[i])
max_money_so_far[0] = prev

Choose a reason for hiding this comment

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

好みかもしれませんが、こうした方が要素をずらしていることが分かりやすいと思いました。

current = max(max_money_so_far[1], max_money_so_far[0] + nums[i])
max_money_so_far[0] = max_money_so_far[1]
max_money_so_far[1] = current

Comment on lines +103 to +104
if len(nums) == 1:
return nums[0]

Choose a reason for hiding this comment

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

どのケースが該当するか少し混乱しました。
rob関数内でlen(nums) == 2のケースで処理しちゃってもいいと思いました。

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.

3 participants