博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Maximum Product Subarray
阅读量:4074 次
发布时间:2019-05-25

本文共 738 字,大约阅读时间需要 2 分钟。

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.

Java代码:

public class Solution {    public int maxProduct(int[] A) {        if (A == null || A.length == 0) {            return 0;        }        int max = A[0], min = A[0], result = A[0];        for (int i = 1; i < A.length; i++) {            int temp = max;            max = Math.max(Math.max(max * A[i], min * A[i]), A[i]);            min = Math.min(Math.min(temp * A[i], min * A[i]), A[i]);            if (max > result) {                result = max;            }        }        return result;    }}
 

转载地址:http://enuni.baihongyu.com/

你可能感兴趣的文章
【leetcode】Pascal's Triangle II (python)
查看>>
如何成为编程高手
查看>>
本科生的编程水平到底有多高
查看>>
Solr及Spring-Data-Solr入门学习
查看>>
python_time模块
查看>>
python_configparser(解析ini)
查看>>
selenium学习资料
查看>>
从mysql中 导出/导入表及数据
查看>>
HQL语句大全(转)
查看>>
几个常用的Javascript字符串处理函数 spilt(),join(),substring()和indexof()
查看>>
javascript传参字符串 与引号的嵌套调用
查看>>
swiper插件的的使用
查看>>
layui插件的使用
查看>>
JS牛客网编译环境的使用
查看>>
9、VUE面经
查看>>
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>