Skip to content

Instantly share code, notes, and snippets.

@codertcet111
Created April 4, 2024 04:31
Show Gist options
  • Save codertcet111/7c5690672db5e3d28dcd2faea5df913b to your computer and use it in GitHub Desktop.
Save codertcet111/7c5690672db5e3d28dcd2faea5df913b to your computer and use it in GitHub Desktop.
Leetcode 53 Maximum Subarray
Leetcode 53 Maximum Subarray
# @param {Integer[]} nums
# @return {Integer}
def max_sub_array(nums)
max = nums[0]
sum = 0
nums.each_with_index do |ele, i|
sum += ele
if sum > max
max = sum
end
if sum < 0
sum = 0
end
end
max
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment