Skip to content

Create 121. Best Time to Buy and Sell Stock.md#37

Open
tokuhirat wants to merge 1 commit intomainfrom
121.-Best-Time-to-Buy-and-Sell-Stock
Open

Create 121. Best Time to Buy and Sell Stock.md#37
tokuhirat wants to merge 1 commit intomainfrom
121.-Best-Time-to-Buy-and-Sell-Stock

Conversation

@tokuhirat
Copy link
Owner


class Solution:
def maxProfit(self, prices: List[int]) -> int:
min_prices_so_far = math.inf

Choose a reason for hiding this comment

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

_so_farは個人的にはつけないです。やや冗長に感じました。
また、max_profitも変数の意味合いとしては同じに感じますが、min_priceのみの理由が気になりました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。_so_far の有無を厳密に使い分けておりませんでした。max_profit は最後に確定した値にフォーカスしていたので _so_far をつけなかった程度です。min_price についても確かに不要かもしれません。

以下のコメントも見つけました。
quinn-sasha/leetcode#24 (comment)

更新していく変数は多いですから明示する必要なければわざわざ言わないことの方が多い

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