Skip to content

Commit a0f7371

Browse files
authored
Merge pull request #1200 from voski/patch-1
Create 0053-Maximum-Subarray.rb
2 parents f89a5b3 + 514160a commit a0f7371

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Diff for: ruby/0053-Maximum-Subarray.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def max_sub_array(nums)
2+
sum = 0
3+
max = -10 * 10 * 10 * 10 - 1
4+
5+
nums.each do |num|
6+
sum += num
7+
max = sum > max ? sum : max
8+
9+
sum = 0 if sum < 0
10+
end
11+
12+
max
13+
end

0 commit comments

Comments
 (0)