Skip to content

Commit 7cde6ce

Browse files
authored
Update max_product_subarray_another_approach.rb
1 parent 16645dc commit 7cde6ce

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

dp/max_product_subarray_another_approach.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
def subarray_with_max_product(arr)
2-
len = arr.length
2+
len = arr.length
33
product_so_far = max_product_end = 1
44
max_start_i = 0
55
so_far_start_i = so_far_end_i = 0
66

77
(0..len-1).each do |i|
88
max_product_end *= arr[i]
9-
109
if max_product_end < 0
1110
max_product_end = 1
1211
max_start_i = i + 1

0 commit comments

Comments
 (0)