Skip to content

Conversation

@Fuminiton
Copy link
Owner

if len(nums) <= 2:
return max(nums)

max_profit = 0
Copy link

Choose a reason for hiding this comment

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

44行目の直前に欲しく思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

いつもレビューありがとうございます。
おっしゃる通りですね。

### 感想
- 先頭を使うケース、使わないケース用に別々の変数セットを用意して、1周のループで解いてしまう解法もあった
- この解き方も思い浮かんだ上で、泥棒によって盗める範囲が変わるような変更への柔軟さ等を加味して、step1の実装を選びたかった。。
- 範囲を与えるより、配列を渡した方が応用範囲が広く、かつコードも単純になって良さそう
Copy link

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:
Copy link

Choose a reason for hiding this comment

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

== 1 のほうが素直ですかね。まあ、趣味の範囲です。

Copy link
Owner Author

Choose a reason for hiding this comment

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

いつもレビューありがとうございます。
「2つ以上ない時」という意図で書いていましたが、「1つだけの時」とした方が自然ですね。

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.

4 participants