Open
Conversation
Mike0121
reviewed
Jun 29, 2025
|
|
||
| class Solution: | ||
| def maxProfit(self, prices: List[int]) -> int: | ||
| min_prices_so_far = math.inf |
There was a problem hiding this comment.
_so_farは個人的にはつけないです。やや冗長に感じました。
また、max_profitも変数の意味合いとしては同じに感じますが、min_priceのみの理由が気になりました。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。_so_far の有無を厳密に使い分けておりませんでした。max_profit は最後に確定した値にフォーカスしていたので _so_far をつけなかった程度です。min_price についても確かに不要かもしれません。
以下のコメントも見つけました。
quinn-sasha/leetcode#24 (comment)
更新していく変数は多いですから明示する必要なければわざわざ言わないことの方が多い
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Problem
121. Best Time to Buy and Sell Stock
Next Ploblem
122. Best Time to Buy and Sell Stock II
言語: Python