Skip to content

53 maximum subarray - #31

Open
MA-yo-TA wants to merge 2 commits into
mainfrom
53-Maximum-Subarray
Open

53 maximum subarray#31
MA-yo-TA wants to merge 2 commits into
mainfrom
53-Maximum-Subarray

Conversation

@MA-yo-TA

@MA-yo-TA MA-yo-TA commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Comment on lines +5 to +19
for num in nums:
sum_so_far += num
prefix_sum.append(sum_so_far)

max_subaray_sum = -float("inf")
min_prefix_sum_so_far = 0
for i in range(len(prefix_sum)):
max_subaray_sum = max(
prefix_sum[i] - min_prefix_sum_so_far,
max_subaray_sum,
)
min_prefix_sum_so_far = min(
prefix_sum[i],
min_prefix_sum_so_far,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

二つのloopは一つにすることができそうです

  • prefix_sum[i] は足し合わせていけばタイムリーにとれる

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。そうですね、以前解いた他の問題でも同じことがあったので注意しておきます

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.

2 participants