Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1a0fff

Browse files
authored
Merge pull requestneetcode-gh#1646 from saip7795/sp/max_sub_array
Create: 53. Maximum Sub Array.rb (Ruby Solution)
2 parentsbb3c957 +38b836c commita1a0fff

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎ruby/0053-maximum-sub-array.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defmax_sub_array(nums)
2+
max_sub=nums[0]
3+
current_sum=0
4+
5+
nums.eachdo |num|
6+
current_sum=0ifcurrent_sum <0
7+
current_sum +=num
8+
max_sub=[max_sub,current_sum].max
9+
end
10+
returnmax_sub
11+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp