Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KS #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

KS #21

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
max_subarray dynamic programming
goblineer authored Oct 18, 2019

Unverified

This user has not yet uploaded their public signing key.
commit fdacf03dd65f57af24fcf18125b4e3bf717a5d5c
15 changes: 11 additions & 4 deletions lib/max_subarray.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
def max(num1, num2)
return num1 > num2 ? num1 : num2
end

# Time Complexity: ?
# Space Complexity: ?
def max_sub_array(nums)
return 0 if nums == nil

raise NotImplementedError, "Method not implemented yet!"

max_now = max = nums[0]

(1...nums.length).each do |i|
max_now = nums[i] > max_now + nums[i] ? nums[i] : max_now + nums[i]
max = max_now if max_now > max
end
Comment on lines +12 to +15

Choose a reason for hiding this comment

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

Very concise

return max
end