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