Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1200 from voski/patch-1
Browse files Browse the repository at this point in the history
Create 0053-Maximum-Subarray.rb
  • Loading branch information
dissesmac authored Sep 30, 2022
2 parents f89a5b3 + 514160a commit a0f7371
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ruby/0053-Maximum-Subarray.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def max_sub_array(nums)
sum = 0
max = -10 * 10 * 10 * 10 - 1

nums.each do |num|
sum += num
max = sum > max ? sum : max

sum = 0 if sum < 0
end

max
end

0 comments on commit a0f7371

Please sign in to comment.