Friday, December 12, 2014

【LeetCode】Maximum Product Subarray

有两个做法一个是暴力双循环
代码:这里

一个是动态规划,维护两个值,一个是的当前最大值,另一个是当前最小值
similar like Maximum Subarray question
difference is the max value could be get from 3 situations
current maxValue * A[i]  if A[i]>0
current minValue * A[i]  if A[i]<0
A[i]  
We need to record current maxValue, current minValue and update them every time get the new product

代码:这里

No comments:

Post a Comment