213. House Robber II#48
Open
skypenguins wants to merge 1 commit into
Open
Conversation
h-masder
reviewed
Jul 13, 2026
|
|
||
| ## Step1 | ||
| ### 方針 | ||
| - 見積: 最大 $n = 100$ 、 計算量: $O(n)$ 、 Pythonの実行時間: $10^{7}$ ステップ/秒 とすると、$10^{-5}$ 秒 |
There was a problem hiding this comment.
計算量、実行時間はやりかたに対して言えることなので、まずその説明が必要だと思います。
Owner
Author
There was a problem hiding this comment.
確かにいきなり見積を書くのは、不自然ですね。ご指摘ありがとうございます。
h-masder
reviewed
Jul 13, 2026
| ### 方針 | ||
| - 見積: 最大 $n = 100$ 、 計算量: $O(n)$ 、 Pythonの実行時間: $10^{7}$ ステップ/秒 とすると、$10^{-5}$ 秒 | ||
| - `198. House Robber` と条件はほぼ同じだが、家が環状(最初の家と最後の家が隣接)に配置されている | ||
| - 環状をなんとかしてただの配列にしようと考えて10分経過 |
There was a problem hiding this comment.
方針のたてかたは、以下のやりとりが参考になるかもしれません。
https://discord.com/channels/1084280443945353267/1206101582861697046/1207380634952011796
h-masder
reviewed
Jul 13, 2026
| if len(nums) <= 1: | ||
| return max(nums, default = 0) | ||
| if len(nums) == 2: | ||
| return max(nums) |
h-masder
reviewed
Jul 13, 2026
|
|
||
| def rob_linear(houses: List[int]) -> int: | ||
| if len(houses) <= 1: | ||
| return max(houses, default = 0) |
There was a problem hiding this comment.
if len(houses) == 1:
return houses[0]のほうが素直に感じます。
h-masder
reviewed
Jul 13, 2026
| if len(nums) == 2: | ||
| return max(nums) | ||
|
|
||
| def rob_linear(houses: List[int]) -> int: |
There was a problem hiding this comment.
関数名は、中身の実装について書くよりも、何を返すかが分かるといいと思います。
この関数は、指定した範囲で盗める最大の金額を返すので、rob_rangeやmax_rob_in_rangeなどが良いかなと思いました。
こちらも参考になるかと思います
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.fcs3httrll4l
Owner
Author
There was a problem hiding this comment.
確かにこのままだと何が返ってくるかは分かりづらいですね。ご指摘ありがとうございます。
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.
213. House Robber II
次回予告: 276. Paint Fence