Leetcode no. 152
来源:互联网 发布:人工智能高清在线观看 编辑:程序博客网 时间:2024/06/14 03:49
152. 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[] nums) { if (nums.length==0) return 0; int max= nums[0]; int prevmax= nums[0]; int prevmin= nums[0]; int curmax, curmin; for (int i=1; i<nums.length; i++) { curmax= Math.max(Math.max(prevmax*nums[i], prevmin*nums[i]), nums[i]); curmin= Math.min(Math.min(prevmax*nums[i], prevmin*nums[i]), nums[i]); max= Math.max(max, curmax); prevmax= curmax; prevmin= curmin; } return max; }}
0 0
- Leetcode no. 152
- Leetcode NO.152 Maximum Product Subarray
- leetCode No.152 Maximum Product Subarray
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Leetcode no. 80
- Unix & Linux笔记(17)
- 字符串的旋转问题
- 基于物理渲染的理论基础
- node中的path模块
- Java类的初始化顺序 (静态变量、静态初始化块、变量、初始化块、构造器)
- Leetcode no. 152
- 在线教育的心得
- 中断处理程序中输出调试信息导致无法计算机无法启动
- NYOJ Distribution---1241第八届
- Linux中的计划任务-Crontab
- EL表达式
- 基于Redis实现分布式锁
- Volley框架初识01
- 记Bstar复赛