Skip to content

122. Best Time to Buy and Sell Stock II#43

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

122. Best Time to Buy and Sell Stock II#43
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-122

Conversation

@skypenguins

Copy link
Copy Markdown
Owner

122. Best Time to Buy and Sell Stock II

次回予告: 153. Find Minimum in Rotated Sorted Array

@skypenguins skypenguins self-assigned this Jul 5, 2026
Comment thread memo.md
# 谷を探す
while i < n - 1 and prices[i] >= prices[i + 1]:
i += 1
valley = prices[i]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

好みの問題かもしれませんが、peakに対するvalleyに違和感を感じました。
peakはその時に最高値という意味がわかりやすいのですが、valleyに対してはpeakほどわかりやすくなかったです。

個人的にはtop-bottomもしくはtop_price - bottom_priceにすると思いました。

軽く調べたところ、金融文脈だと peak-troughという語彙があるそうです。

Comment thread memo.md
if profit > 0:
total_profit += profit
cheapest_price = float("inf")
profit = 0

@nodchip nodchip Jul 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

18 行目と 26 行目の profit = 0 は、 22 行目の代入文で上書きされるため、不要だと思いました。

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.

3 participants