[LeetCode] Maximum Product Subarray
2014-10-22 12:05
295 查看
找出最大产品量
Find the contiguous subarray within an array (containing at least one number) which has the largest product.
https://oj.leetcode.com/problems/maximum-product-subarray/
For example, given the array
the contiguous subarray
啊啊啊。做不出来`~~~~
1. 最笨的解答办法
Find the contiguous subarray within an array (containing at least one number) which has the largest product.
https://oj.leetcode.com/problems/maximum-product-subarray/
For example, given the array
[2,3,-2,4],
the contiguous subarray
[2,3]has the largest product =
6.
啊啊啊。做不出来`~~~~
1. 最笨的解答办法
public class Solution { public int maxProduct(int[] A) { if( A.length<1) return 0; int sum = A[0]; int cur = A[0]; for( int i=1; i<A.length ; i++) { sum = sum = maxProductByN( A , i ); } return sum; } public int maxProductByN(int[] A ,int n) { if( A.length<1) return 0; int sum = A[0]; int cur = A[0]; for(int j=0;j<A.length-n;j++){ for( int i=j; i<j+n; i++) { cur *= A[i]; } sum = sum < cur ? cur : sum; } return sum; } }
相关文章推荐
- 151_leetcode_Maximum Product Subarray
- Leetcode Maximum Product Subarray
- [leetcode 152] Maximum Product Subarray
- Leetcode---Maximum Product Subarray
- LeetCode Maximum Product Subarray
- Leetcode 152 Maximum Product Subarray
- leetcode Maximum Product Subarray
- 【LeetCode】Maximum Product Subarray
- Maximum Product Subarray--leetcode
- LeetCode - Maximum Product Subarray
- leetcode--Maximum Product Subarray
- Leetcode_Maximum Product Subarray(c++ version)
- Java for LeetCode 152 Maximum Product Subarray
- 1 Maximum Product Subarray_Leetcode
- [Leetcode 152, Medium] Maximum Product Subarray
- LeetCode Maximum Product Subarray(枚举)
- Maximum Product Subarray -- leetcode
- [LeetCode]Maximum Product Subarray
- 【Leetcode】Maximum Product Subarray
- LeetCode 笔记26 Maximum Product Subarray