From 8519e419faa8e39f4ca969de387bd48f21ef412a Mon Sep 17 00:00:00 2001 From: sidaksohi <31377210+sidaksohi@users.noreply.github.com> Date: Wed, 25 Aug 2021 15:41:20 -0700 Subject: [PATCH] Update maximum_subarray.rb --- data_structures/arrays/maximum_subarray.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data_structures/arrays/maximum_subarray.rb b/data_structures/arrays/maximum_subarray.rb index 5c85167..ad2059e 100644 --- a/data_structures/arrays/maximum_subarray.rb +++ b/data_structures/arrays/maximum_subarray.rb @@ -21,7 +21,7 @@ -#Sliding Window Approach - O(n) Time / O(1) Space +#Dynamic Programming Approach (Kadane's Algorithm) - O(n) Time / O(1) Space #Init max_sum as first element #Return first element if the array length is 1 #Init current_sum as 0 @@ -29,7 +29,7 @@ #if current_sum < 0, then reset it to 0 (to eliminate any negative prefixes) #current_sum += num #max_sum = current_sum if current_sum is greater than max_sum -#Return max_sum +#Return max_sum # @param {Integer[]} nums @@ -53,4 +53,4 @@ def max_sub_array(nums) #return answer max_sum -end \ No newline at end of file +end