Skip to content

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

Open
tom4649 wants to merge 2 commits intomainfrom
122.Best-Time-to-Buy-and-Sell-Stock-II
Open

122. Best Time to Buy and Sell Stock II#36
tom4649 wants to merge 2 commits intomainfrom
122.Best-Time-to-Buy-and-Sell-Stock-II

Conversation

@tom4649
Copy link
Copy Markdown
Owner

@tom4649 tom4649 commented Mar 29, 2026

122/sol2.py Outdated
Comment on lines +3 to +4
if not prices:
raise ValueError("The input list is empty")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

sol1.py と処理が変わってますが、どっちがいいですかね。

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.

0を返す方が適切なように考え直しました。入力が空のときにprofitが0となるのは自然で、この場合にわざわざプログラムを停止させるのは使い勝手が悪そうですので。

122/sol2.py Outdated
Comment on lines +15 to +18
profit_holding_stock, profit_not_holding_stock = (
next_profit_holding_stock,
next_profit_not_holding_stock,
)
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

@tom4649 tom4649 Mar 29, 2026

Choose a reason for hiding this comment

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

swapするわけではないので多重代入する必要はないですね

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.

2 participants