原题地址

简单动态规划,跟最大子串和类似。

一维状态空间可以经过压缩变成常数空间。

代码:

 int maxProduct(int A[], int n) {
if (n <= )
return ; int res = A[n - ];
int minp = A[n - ];
int maxp = A[n - ]; for (int i = n - ; i >= ; i--) {
int tmp = minp;
minp = min(A[i], min(A[i] * minp, A[i] * maxp));
maxp = max(A[i], max(A[i] * tmp, A[i] * maxp));
res = max(res, maxp);
} return res;
}

Leetcode#152 Maximum Product Subarray的更多相关文章

  1. 求连续最大子序列积 - leetcode. 152 Maximum Product Subarray

    题目链接:Maximum Product Subarray solutions同步在github 题目很简单,给一个数组,求一个连续的子数组,使得数组元素之积最大.这是求连续最大子序列和的加强版,我们 ...

  2. [LeetCode] 152. Maximum Product Subarray 求最大子数组乘积

    Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...

  3. LeetCode 152. Maximum Product Subarray (最大乘积子数组)

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  4. Java for LeetCode 152 Maximum Product Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  5. leetcode 152. Maximum Product Subarray --------- java

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  6. C#解leetcode 152. Maximum Product Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  7. [leetcode]152. Maximum Product Subarray最大乘积子数组

    Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...

  8. leetcode 53. Maximum Subarray 、152. Maximum Product Subarray

    53. Maximum Subarray 之前的值小于0就不加了.dp[i]表示以i结尾当前的最大和,所以需要用一个变量保存最大值. 动态规划的方法: class Solution { public: ...

  9. 152. Maximum Product Subarray - LeetCode

    Question 152. Maximum Product Subarray Solution 题目大意:求数列中连续子序列的最大连乘积 思路:动态规划实现,现在动态规划理解的还不透,照着公式往上套的 ...

随机推荐

  1. 线程间通信--wait和notify

    使用wait.notify方法实现线程间的通信(注意这两个方法都是object的类的方法,换句话说java为所有的对象都提供了这两个方法) 1.wait和notify必须配合synchronized关 ...

  2. ajax+php+mysql更新

    html代码 <input type="button" id="quxiao" class="quxiao" name="q ...

  3. Microsoft Visual C++ Runtime error解决方法

    1: 当出现下图时提示Microsoft Visual C++ Runtime error 2:此时不要关闭该对话框,然后打开任务管理器(Ctrl+Shift+Esc)如下图: 找到Microsoft ...

  4. VMware虚拟机升级过程中遇到的一点问题

    在将VWware由9.0升级到10.0的过程中,出现如下图的错误:        failed to create the requested registry key Key:Installer e ...

  5. How to create Lookup Worker Filtered by Legal Entity[AX2012]

    1. Add a new method in hcmWorker table, and add this script : public static client void lookupWorker ...

  6. 压力测试之TCPP

    1.下载源码 tpcc-mysql-src.tgz 2.解压 tpcc-mysql-src.tgz 3.安装 [root@DBMysql mysql]# cd /home/mysql/tpcc-mys ...

  7. 在linux下安装Mongodb

    1.到官网下载源码:mongodb-linux-x86_64-rhel55-3.2.4.gz 2.安装 创建用户组.用户.目录 [root@hadoop1 ~]# groupadd mongodb [ ...

  8. .Net 自己写个简单的 半 ORM (练手)

    ORM 大家都知道, .Net 是EF  还有一些其他的ORM  从JAVA 中移植过来的 有 , 大神自己写的也有 不管ORM 提供什么附加的 乱七八糟的功能 但是 最主要的 还是 关系映射 的事情 ...

  9. python 逻辑运算符与比较运算符的差别

    文章内容摘自:http://www.cnblogs.com/vamei/archive/2012/05/29/2524376.html 逻辑运算符 and, or, not 比较运算符 ==, !=, ...

  10. ios category

    https://github.com/shaojiankui/IOS-Categories