-
Notifications
You must be signed in to change notification settings - Fork 0
Solved: 213. House Robber II #36
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
base: main
Are you sure you want to change the base?
Conversation
| if len(nums) <= 2: | ||
| return max(nums) | ||
|
|
||
| max_profit = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
44行目の直前に欲しく思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いつもレビューありがとうございます。
おっしゃる通りですね。
| ### 感想 | ||
| - 先頭を使うケース、使わないケース用に別々の変数セットを用意して、1周のループで解いてしまう解法もあった | ||
| - この解き方も思い浮かんだ上で、泥棒によって盗める範囲が変わるような変更への柔軟さ等を加味して、step1の実装を選びたかった。。 | ||
| - 範囲を与えるより、配列を渡した方が応用範囲が広く、かつコードも単純になって良さそう |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
関数内関数がO(N)なので、スライスの計算量が実行時間に大きな影響を与えることはなさそうですね。
| def rob(self, nums: List[int]) -> int: | ||
| if not nums: | ||
| return 0 | ||
| if len(nums) < 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== 1 のほうが素直ですかね。まあ、趣味の範囲です。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いつもレビューありがとうございます。
「2つ以上ない時」という意図で書いていましたが、「1つだけの時」とした方が自然ですね。
213. House Robber II