Skip to content

Commit a1a0fff

Browse files
authored
Merge pull request neetcode-gh#1646 from saip7795/sp/max_sub_array
Create: 53. Maximum Sub Array.rb (Ruby Solution)
2 parents bb3c957 + 38b836c commit a1a0fff

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+
def max_sub_array(nums)
2+
max_sub = nums[0]
3+
current_sum = 0
4+
5+
nums.each do |num|
6+
current_sum = 0 if current_sum < 0
7+
current_sum += num
8+
max_sub = [max_sub,current_sum].max
9+
end
10+
return max_sub
11+
end

0 commit comments

Comments
 (0)