Open
Conversation
mamo3gr
reviewed
Mar 25, 2026
Comment on lines
+46
to
+47
| for i in range(len(prices) - 1): | ||
| profit = prices[i + 1] - prices[i] |
There was a problem hiding this comment.
細かいですが「i 日目の利益 (profit) は、i + 1 日目での売値 - i 日目の買値」よりも、「i + 1日目の利益は〜」の方が、自然言語での説明に近いと思いました。
Suggested change
| for i in range(len(prices) - 1): | |
| profit = prices[i + 1] - prices[i] | |
| for i in range(1, len(prices)): | |
| profit = prices[i + 1] - prices[i] |
There was a problem hiding this comment.
rangeの範囲をそのようにするとprofitは
profit = prices[i] - prices[i - 1]にしないと上手くいかない気がします.
Owner
Author
There was a problem hiding this comment.
ありがとうございます。
見込み利益、みたいなことを考えていたのでループの範囲に違和感を持ちませんでした。
コードでは表現できていないので、その辺まで考えて提示いただいた方がより読みやすいですね。
5ky7
reviewed
Mar 25, 2026
Comment on lines
+46
to
+47
| for i in range(len(prices) - 1): | ||
| profit = prices[i + 1] - prices[i] |
There was a problem hiding this comment.
rangeの範囲をそのようにするとprofitは
profit = prices[i] - prices[i - 1]にしないと上手くいかない気がします.
Comment on lines
+97
to
+100
| - `return max_return_without_stock` でも正しい | ||
| - ただ、パッとは理解できなかった | ||
| - max を使うことによるペナルティは特に大きくない気がするので、何も考えずに書いてしまう気がする | ||
| - 気を回せるようになるのがもちろん良い |
There was a problem hiding this 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.
今回の問題
Best Time to Buy and Sell Stock II - LeetCode
使用言語
Python