53 maximum subarray#32
Open
tarinaihitori wants to merge 2 commits into
Open
Conversation
fuga-98
reviewed
May 12, 2025
|
|
||
| max_sum = nums[0] | ||
| for i in range(1, nums_length + 1): | ||
| for j in range(i): |
Fuminiton
reviewed
May 13, 2025
| max_sum = nums[0] | ||
| for i in range(1, nums_length + 1): | ||
| for j in range(i): | ||
| max_sum = max(max_sum, prefix_sum[i] - prefix_sum[j]) |
There was a problem hiding this comment.
好みの範囲だと思いますが、jはiと関連のある命名をしたくなります。
その方が読み手が受け取れる情報が増えると思うからです。
oda
reviewed
May 13, 2025
| ``` | ||
|
|
||
| kadaneのアルゴリズムの解き方。 | ||
| 1つ前の状態のみ覚えておけばいいので配列を使わずsum変数のみで対応できる。賢いアルゴリズムだ。 |
There was a problem hiding this comment.
https://discord.com/channels/1084280443945353267/1206101582861697046/1207749510797992026
https://discord.com/channels/1084280443945353267/1206101582861697046/1208414507735453747
私は、Kadane の手前に、もう少し解法がある気がするので、このあたりを読んでおいてください。
nodchip
reviewed
May 14, 2025
| @@ -0,0 +1,126 @@ | |||
| 1st | |||
|
|
|||
| 二重ループで ij の範囲内で足し合わせ、その最大値を返せばいける...と思ったが、TLE | |||
There was a problem hiding this comment.
時間計算量は求めましたか?また、時間計算量からおおよその実行時間を見積もりましたか?
時間計算量からおおよその実行時間を見積もる方法については、以下のコメント等が役に立つと思います。
https://discord.com/channels/1084280443945353267/1307605446538039337/1336992875577081917
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.
https://leetcode.com/problems/maximum-subarray/description/