Skip to content

213. House Robber II#48

Open
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-213
Open

213. House Robber II#48
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-213

Conversation

@skypenguins

@skypenguins skypenguins commented Jul 13, 2026

Copy link
Copy Markdown
Owner

213. House Robber II

次回予告: 276. Paint Fence

@skypenguins skypenguins self-assigned this Jul 13, 2026
Comment thread memo.md

## Step1
### 方針
- 見積: 最大 $n = 100$ 、 計算量: $O(n)$ 、 Pythonの実行時間: $10^{7}$ ステップ/秒 とすると、$10^{-5}$ 秒

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

計算量、実行時間はやりかたに対して言えることなので、まずその説明が必要だと思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

確かにいきなり見積を書くのは、不自然ですね。ご指摘ありがとうございます。

Comment thread memo.md
### 方針
- 見積: 最大 $n = 100$ 、 計算量: $O(n)$ 、 Pythonの実行時間: $10^{7}$ ステップ/秒 とすると、$10^{-5}$ 秒
- `198. House Robber` と条件はほぼ同じだが、家が環状(最初の家と最後の家が隣接)に配置されている
- 環状をなんとかしてただの配列にしようと考えて10分経過

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

方針のたてかたは、以下のやりとりが参考になるかもしれません。
https://discord.com/channels/1084280443945353267/1206101582861697046/1207380634952011796

Comment thread memo.md
if len(nums) <= 1:
return max(nums, default = 0)
if len(nums) == 2:
return max(nums)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

22行目~23行目は不要だと思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

確かに不要ですね。

Comment thread memo.md

def rob_linear(houses: List[int]) -> int:
if len(houses) <= 1:
return max(houses, default = 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

            if len(houses) == 1:
                return houses[0]

のほうが素直に感じます。

Comment thread memo.md
if len(nums) == 2:
return max(nums)

def rob_linear(houses: List[int]) -> int:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

関数名は、中身の実装について書くよりも、何を返すかが分かるといいと思います。
この関数は、指定した範囲で盗める最大の金額を返すので、rob_rangemax_rob_in_rangeなどが良いかなと思いました。

こちらも参考になるかと思います
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.fcs3httrll4l

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

確かにこのままだと何が返ってくるかは分かりづらいですね。ご指摘ありがとうございます。

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants