Maximum Product Subarray
来源:互联网 发布:a5源码网 编辑:程序博客网 时间:2024/05/22 13:39
Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.
For example, given the array [2,3,-2,4]
,
the contiguous subarray [2,3]
has the largest product = 6
.
public class Solution { public int maxProduct(int[] A) { if (A == null || A.length == 0) { return 0; } int max = A[0], min = A[0], result = A[0]; for (int i = 1; i < A.length; i++) { int temp = max; max = Math.max(Math.max(max * A[i], min * A[i]), A[i]); min = Math.min(Math.min(temp * A[i], min * A[i]), A[i]); if (max > result) { result = max; } } return result; }}
0 0
- LeetCode_Maximum Subarray | Maximum Product Subarray
- Maximum Product Subarray
- Maximum Product Subarray
- 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
- Maximum Product Subarray
- Maximum Product Subarray
- [LeetCode]Maximum Product Subarray
- Leetcode Maximum Product Subarray
- 8皇后问题(递归方法实现)
- 图的基本习题集锦
- Android入门2——无法创建模拟器解决
- CSS常用网页标签初始化
- 最好用Unity 3D制作小地图,显示、隐藏小地图和背景音乐播放与暂停 [复制链接]
- Maximum Product Subarray
- socket中的几个数据结构
- STM32摘录
- myeclipse8.5集成SVN1.6.x
- Python的unittest自动化测试框架
- QT编程实例1--简单的文本编辑器(下)
- GRASP设计模式及OO设计原则浅谈
- Unity+NGUI打造网络图片异步加载与本地缓存工具类
- UITableViewCell的seleced与deselect 选中 取消选中