Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.

Example 1:

Input: [2,3,-2,4]
Output: 6
Explanation: [2,3] has the largest product 6.

Example 2:

Input: [-2,0,-1]
Output: 0
Explanation: The result cannot be 2, because [-2,-1] is not a subarray.



class Solution {
public:
int maxProduct(vector<int>& nums) {
int ans=nums[],frontprod=,backprod=;
int n=nums.size();
for(int i=;i<n;i++){
frontprod*=nums[i];
backprod*=nums[n-i-];
ans=max(ans,max(frontprod,backprod));
frontprod=frontprod == ? :frontprod;
backprod=backprod == ? : backprod; }
return ans;
}
};

最新文章

  1. 95、Jenkins部署.net持续集成自动化测试环境
  2. Codeforces Round #339 (Div.2)
  3. 查看Exchange邮件队列(queue)
  4. PHP5 mysqli 教程
  5. Git ~ 添加远程仓库 ~Git
  6. HDU 1023 Train Problem II (卡特兰数,经典)
  7. sql server2012 动态端口
  8. DJANGO:根据不同的环境,配置不同的SETTINGS文件,读取不同的DB,JENKINS,SALT配置
  9. Xcode的控制台调试命令
  10. Java程序员面试题集(51-70)(转)
  11. 关于URL编码的问题
  12. RNTools
  13. CHD4 impala安装配置
  14. zzw原创_ipv6下环境配置防火墙及FTP处理一例
  15. Tesseract
  16. Servlet-转发和重定向的区别
  17. the import XXXX cannot be resolved 解决方法
  18. VMware网络桥接模式与NAT模式共存
  19. 【VB.NET】利用 ZXing.Net 生成二维码(支持自定义LOGO)
  20. LeetCode-206.ReverseLinked List

热门文章

  1. Ajax缓存
  2. jdk1.8换成1.7
  3. Oracle锁处理、解锁方法
  4. ps基本认识
  5. 【vue】------浅谈vue------【William】
  6. ElasticSearch优化系列四:ES的heap是如何被瓜分掉的
  7. Leecode刷题之旅-C语言/python-231 2的幂
  8. A1070
  9. 一个没有成就而即将退赛的OIer的告别书
  10. 20155216 实验一《Java开发环境的熟悉》实验报告