We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e676e28 commit 8519e41Copy full SHA for 8519e41
data_structures/arrays/maximum_subarray.rb
@@ -21,15 +21,15 @@
21
22
23
24
-#Sliding Window Approach - O(n) Time / O(1) Space
+#Dynamic Programming Approach (Kadane's Algorithm) - O(n) Time / O(1) Space
25
#Init max_sum as first element
26
#Return first element if the array length is 1
27
#Init current_sum as 0
28
#Iterate through the array:
29
#if current_sum < 0, then reset it to 0 (to eliminate any negative prefixes)
30
#current_sum += num
31
#max_sum = current_sum if current_sum is greater than max_sum
32
-#Return max_sum
+#Return max_sum
33
34
35
# @param {Integer[]} nums
@@ -53,4 +53,4 @@ def max_sub_array(nums)
53
54
#return answer
55
max_sum
56
-end
+end
0 commit comments