Open
Conversation
oda
reviewed
May 5, 2025
| }; | ||
| ``` | ||
|
|
||
| 番兵を使わず、i = 0の時だけ特別扱いする |
There was a problem hiding this comment.
この変形をする場合、同値なコードにするには nums の長さが1以上かを確認する必要がありますね。
(必要かはともかく。)
hroc135
reviewed
May 6, 2025
| for (int i = 0; i < nums.size(); i++) { | ||
| cumulative_sum += nums[i]; | ||
| max_subarray_sum = std::max(max_subarray_sum, cumulative_sum - min_cumulative_sum_ever); | ||
| min_cumulative_sum_ever = std::min(min_cumulative_sum_ever, cumulative_sum); |
There was a problem hiding this comment.
_ever がなくても伝わるかなと思いました。
他の解法も含めて全体的に読みやすかったです。
nodchip
reviewed
May 6, 2025
| public: | ||
| int maxSubArray(std::vector<int>& nums) { | ||
| int diff_from_bottom = 0; | ||
| int max_subarray_sum = INT_MIN; |
There was a problem hiding this comment.
INT_MIN は C 言語風に感じます。 C++ では std::numeric_limits::min() という書き方をよく見かけるように思います。チームの標準的な書き方に合わせることをお勧めいたします。
Fuminiton
reviewed
May 6, 2025
| } | ||
| return *std::max_element(max_subarray_sum_at.begin(), max_subarray_sum_at.end()); | ||
| } | ||
| }; |
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
Maximum Subarray
Next Problem
Unique Paths