August 10, 2015
Find the contiguous subarray within an array (containing at least one number)
which has the largest product.
which has the largest product.
For example, given the array [2,3,-2,4],
the contiguous subarray [2,3] has the largest product = 6.
the contiguous subarray [2,3] has the largest product = 6.
Two approaches, one is dynamic programming DP implementation, another is the greedy method.
DP solution:
Greedy algorithm:
read the blog first,
http://fmarss.blogspot.ca/2014/10/leetcode-solution-maximum-product.html
and then, convert it to C# programming language,
read the blog first,
http://fmarss.blogspot.ca/2014/10/leetcode-solution-maximum-product.html
and then, convert it to C# programming language,
No comments:
Post a Comment