[leetcode] Maximum Product Subarray
来源:互联网 发布:中国电信cn2网络 编辑:程序博客网 时间:2024/05/01 11:42
<span style="white-space:pre"></span>public int maxProduct(int[] A, int start, int end) { int product = 1; int leftProduct = 1; for(int i = start; i <= end; i++) { product *= A[i]; } int max = product; for(int i = start; i < end; i++) { leftProduct *=A[i]; int rightProduct = product/leftProduct; max = Math.max(leftProduct, max); max = Math.max(rightProduct, max); } return max; } public int maxProduct(int A[]) { int max = Integer.MIN_VALUE; int start = 0; for(int i = 0; i < A.length; i++) { if(A[i] == 0) { if(start <= i-1) { max = Math.max(max, maxProduct(A, start, i-1)); } max = Math.max(0, max); start = i+1; } } if(start < A.length) max = Math.max(max, maxProduct(A, start, A.length-1)); return max; }
0 0
- Maximum Product Subarray 【LeetCode】
- [LeetCode] Maximum Product Subarray
- leetcode-Maximum Product Subarray
- Maximum Product Subarray -- LeetCode
- LeetCode-Maximum Product Subarray
- [LeetCode]Maximum Product Subarray
- [LeetCode]Maximum Product Subarray
- 【LeetCode】Maximum Product Subarray
- leetcode:Maximum Product Subarray
- leetcode: Maximum Product Subarray
- Leetcode: Maximum Product Subarray
- [LeetCode]Maximum Product Subarray
- Leetcode Maximum Product Subarray
- [Leetcode]Maximum Product Subarray
- Leetcode--Maximum Product Subarray
- Maximum Product Subarray [leetcode]
- LeetCode | Maximum Product Subarray
- LeetCode-Maximum Product Subarray
- 9种排序算法性能之比较之----插入排序
- (待解决)XNA “System.OutOfMemoryException” 内存溢出?
- Linux 目录和文件的默认访问权限——umask
- linux0.11学习笔记(2)
- 1的个数
- [leetcode] Maximum Product Subarray
- 二叉树前序遍历的非递归实现(京东笔试考过)
- java获取中国城市代码 中国城市ID(天气预报可用哦)
- 欧几里德游戏
- poj 2513 Colored Sticks(欧拉通路+并查集+字典树)
- spark调优经验(待续)
- android图片导致bin文件夹和apk很大
- hdu 4465 求期望
- 【AC自动机】 BZOJ 2434 [Noi2011]阿狸的打字机