Skip to content

Conversation

@docto-rin
Copy link
Owner


- レビュー by GPT-5
- > 「上がった日だけ都度差分を足す」貪欲解が最適。
- 確かに。現実の株の売買回数を減らしたい気持ちが邪魔してこれは思いつかなかった。
Copy link

Choose a reason for hiding this comment

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

株を持って日を超すか持たないで日を超すかの2択なので、それぞれどちらがよかったかを翌日に決めればいいということです。

if prices[i + 1] - prices[i] >= 0:
continue
total_profit += prices[i] - extremum
extremum = prices[i]
Copy link

@shintaro1993 shintaro1993 Oct 29, 2025

Choose a reason for hiding this comment

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

勘違いしていたら申し訳ないのですが、利益確定後の prices[i] の情報は使われていないと思うのでこの行は消してもいいのかなと思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

正しいです。削除すべきですね。

for i in range(1, len(prices)):
total_profit += max(0, prices[i] - prices[i - 1])
return total_profit
```

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants