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.

子数组乘积最大

class Solution {
public:
int maxProduct(int A[], int n) {
if(n < ) return ;
int minv = A[], maxv = A[], res = A[];
for(int i = ; i < n; ++ i){
int tmpMin = min(minv*A[i],maxv*A[i]);
int tmpMax = max(minv*A[i],maxv*A[i]);
minv = min(tmpMin,A[i]);
maxv = max(tmpMax,A[i]);
res=max(maxv,res);
}
return res; };

最新文章

  1. zabbix3.0 安装Tips
  2. 从零开始学习jQuery (一) 入门篇
  3. Proactor VS Reactor
  4. linux中shell变量$#,$@,$*,$?,$$,$!,$_,$0,$1,$2的含义解释
  5. 连接别人创建的ORACLE数据库
  6. c# 将页面导出到word(含图片及控件)
  7. openCV 直方图统计
  8. leetcode@ [116/117] Populating Next Right Pointers in Each Node I &amp; II (Tree, BFS)
  9. 如何配置SSH Keys登录
  10. Frequent values
  11. CSS Reset方法
  12. Linq4j简明介绍
  13. POJ 2350 Above Average
  14. json-java处理-jackson
  15. Python 高度定制化自己的线程类和进程类代码,获取启动进程或线程方法的结果(兼容Py2和Py3)
  16. ssh的用户配置文件config管理ssh会话
  17. bootstrap3在IE8下导航不显示,自动识别成手机模式
  18. Orleans逐步教程
  19. VS打包项目详细解析
  20. maven使用出现的错误

热门文章

  1. PX 和PT的区别
  2. xampp 下安装mysql-python
  3. linux 下Qt WebEngine 程序打包简单记录
  4. 关于settimeout 和for循环
  5. Android Studio accelerator key(shortcut)&amp; Basic knowledge
  6. wget 扒站
  7. Cocos2dx
  8. 值得推荐的C/C++框架和库
  9. 21. Merge Two Sorted Lists —— Python
  10. Qt在ui中使用代码添加新的控件