Skip to content

53 maximum subarray#32

Open
tarinaihitori wants to merge 2 commits into
mainfrom
53-maximum-subarray
Open

53 maximum subarray#32
tarinaihitori wants to merge 2 commits into
mainfrom
53-maximum-subarray

Conversation

@tarinaihitori
Copy link
Copy Markdown
Owner

Comment thread 53. Maximum Subarray.md

max_sum = nums[0]
for i in range(1, nums_length + 1):
for j in range(i):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

関数にしても良いと思いました。

Comment thread 53. Maximum Subarray.md
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])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

好みの範囲だと思いますが、jiと関連のある命名をしたくなります。
その方が読み手が受け取れる情報が増えると思うからです。

Comment thread 53. Maximum Subarray.md
```

kadaneのアルゴリズムの解き方。
1つ前の状態のみ覚えておけばいいので配列を使わずsum変数のみで対応できる。賢いアルゴリズムだ。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

https://discord.com/channels/1084280443945353267/1206101582861697046/1207749510797992026

https://discord.com/channels/1084280443945353267/1206101582861697046/1208414507735453747

私は、Kadane の手前に、もう少し解法がある気がするので、このあたりを読んでおいてください。

Comment thread 53. Maximum Subarray.md
@@ -0,0 +1,126 @@
1st

二重ループで ij の範囲内で足し合わせ、その最大値を返せばいける...と思ったが、TLE
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

時間計算量は求めましたか?また、時間計算量からおおよその実行時間を見積もりましたか?

時間計算量からおおよその実行時間を見積もる方法については、以下のコメント等が役に立つと思います。
https://discord.com/channels/1084280443945353267/1307605446538039337/1336992875577081917

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.

5 participants