Skip to content

Commit 8519e41

Browse files
authored
Update maximum_subarray.rb
1 parent e676e28 commit 8519e41

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

data_structures/arrays/maximum_subarray.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121

2222

2323

24-
#Sliding Window Approach - O(n) Time / O(1) Space
24+
#Dynamic Programming Approach (Kadane's Algorithm) - O(n) Time / O(1) Space
2525
#Init max_sum as first element
2626
#Return first element if the array length is 1
2727
#Init current_sum as 0
2828
#Iterate through the array:
2929
#if current_sum < 0, then reset it to 0 (to eliminate any negative prefixes)
3030
#current_sum += num
3131
#max_sum = current_sum if current_sum is greater than max_sum
32-
#Return max_sum
32+
#Return max_sum
3333

3434

3535
# @param {Integer[]} nums
@@ -53,4 +53,4 @@ def max_sub_array(nums)
5353

5454
#return answer
5555
max_sum
56-
end
56+
end

0 commit comments

Comments
 (0)