LeetCode Maximum Product Subarray

Cadence Allegro 17.4学习记录开始02-原理图Capture CIS 17.4 Allegro的第一方网表与第三方网表有以下几个区别点;Ø 与Allegro实现交互式操作的是第一方网表,第三方网表时不可以实现交互式操作;Ø 第三方网表不能将器件的Value属性导入到PCB中,输出时以封装属性来代替Value属性,第一方网表是可以的;Ø 网表导入到PCB中时,第三方的网表需要指定事先指定好PCB封装库文件,并产生Device文件,才可以将网表导入到PCB中,第一方网表则可以直接导入。 阅读详情

原题链接在这里:https://leetcode.com/problems/maximum-product-subarray/

与Maximum Subarray类似。但出了要维护一个局部最大量外还需要同时多维护一个局部最小量。

e.g.[-2,3,-4], 若不维护局部最小量,i = 1时,局部最大是3,全局最大也是3,i=2时 局部最大变成-4,全局最大变成3,但实际全局最大应该是8. 这是因为负数与负数相乘可能会产生一个很大的正数,与加法只要是负一定变小不同。

所以要同时维护一个局部最小变量,以防当前值是负数。

AC Java:

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


华为OD机考真题 新系统 9月23号 【世界杯徽章换购】多语言题解 华为OD机试真题 新系统【世界杯徽章换购】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【世界杯徽章换购】多语言题解。 阅读详情

相关推荐

NVIDIA Jetson AGX Xavier设置风扇转速、工作模式及性能监控

Xavier的风扇在开机之后是默认关闭的,每次重启都需要手动打开风扇,后续可能考虑修改bashrc文件进行自动开启 这个是显示当前风扇的转速,默认应该是0,表示关闭,最大是250 cat /sys/devices/pwm-fan/target_pwm 可以通过修改该文件的值来修改风扇转速 vim /sys/devices/pwm-fan/target_pwm 我一般使用的是100这个值 作者:ryan_ren 链接:https://www.jianshu.com/p/d3c2041f7f7d 来源:简书 著

weixin_43877080的博客 1万+

LeetCode 53/152 Maximum Subarray/Maximum Product Subarray(动态规划)

LeetCode 53/152 Maximum Subarray/Maximum Product Subarray(动态规划)

花事未了_喃喃语 436

RV1126双摄IMX577驱动移植避坑:从RK3588到RV1126的dts配置与内存崩溃解决实录

本文详细记录了在RV1126平台上移植RK3588的IMX577双摄驱动的完整过程,重点解决了dts配置与内存崩溃问题。通过分析硬件架构差异、驱动移植关键点及CMA内存越界问题,提供了两种有效解决方案,并分享了双摄同步优化与网络调试的实战经验,为嵌入式视觉系统开发提供实用参考。

weixin_42641741的博客 405

LeetCode 152. Maximum Product Subarray(动态规划)

题目来源:https://leetcode.com/problems/maximum-product-subarray/ 问题描述 152.Maximum Product Subarray Medium Given an integer arraynums, find the contiguous subarray within an array (containing at leas...

da_kao_la的博客 308

TWR-K65F180M评估板:基于Cortex-M4的嵌入式原型开发实战指南

在嵌入式系统开发中,微控制器(MCU)是核心,而围绕其构建的硬件平台则是将想法转化为可工作原型的关键。Cortex-M4内核凭借其高效的流水线、DSP指令集和浮点单元,为实时控制与信号处理提供了强大的运算能力。其技术价值在于,能够在较低功耗下满足工业控制、物联网网关等场景对能效比的严苛要求。为了快速验证系统设计,开发者常使用成熟的评估板来规避底层硬件设计的风险,直接聚焦于应用开发。本文以恩智浦的TWR-K65F180M评估板为例,深入解析其基于**ARM Cortex-M4**内核的K65 MCU的硬件架构

weixin_33582311的博客 370

Ubuntu升级遇到grub-efi-amd64-signed报错?3步搞定这个烦人的EFI目录问题

本文详细解析了Ubuntu系统升级时遇到的“grub-efi-amd64-signed”报错及“cannot find EFI directory”问题。通过剖析UEFI启动机制与EFI系统分区原理,提供了从诊断到修复的三步解决方案,帮助用户快速解决因EFI目录未挂载导致的升级中断,确保系统引导正常。

assembly8low的博客 584

Leetcode 152. Maximum Product Subarray

Leetcode 152. Maximum Product Subarray if there’s no zero in the array, then the subarray with maximum product must start with the first element or end with the last element. 例子: 关于0: [0, 100, 0] return 100; 关于负号: [-1, 2, 3] [1, 2, -3] [-1, 2, -3] class So

weixin_43876597的博客 161

在windows中安装并启动ActiveMQ5.16.2

打开ActiveMQ官网 下载ActiveMQ 点击apache-activemq-5.16.2-bin.zip进行下载 下载发后解压到c盘根目录下 在powershell中输入 ./activemq start启动 ActiveMQ服务 htpp://127.0.0.1:8161访问ActiveMQ控制台 ...

934

[LeetCode]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

coder 进阶的专栏 5530

PR工具timing report中setup time的计算过程

然后去pr工具里报告report_delay_calculation/reportDelayCalculation -from related_pin -to constraint_pin。这里constraint pin就是D pin (D0 D1 D2 D3),related pin就是 CK pin。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 454

人工智能算法面试大总结-总目录

涉及秋招、春招、社招

啥都生的博客 2万+

【LeetCode】Maximum Subarray 和 Maximum Product Subarray

53. Maximum Subarray 152. Maximum Product Subarray

夏至亦韵 296

AI翻译工具自动翻译日语视频生成srt中文字幕,支持离线轻松生成任意日语视频字幕!可选择支持显卡模式和cpu模式低显存也能用

【AI离线字幕神器:日语视频一键转中文字幕】推荐一款基于Faster-Whisper的本地化字幕工具,可离线生成日语视频的中文字幕(.srt格式),支持CPU/GPU加速处理。实测1小时视频最快4-5分钟完成翻译,无需联网保护隐私。操作简单只需拖拽文件,支持批量处理音频(mp3/wav)和视频(mp4/mkv)文件,还能自定义输出格式和参数调整。特别适合需要观看无字幕日语资料的用户,堪称技术宅必备神器。下载地址附后,包含详细使用教程和参数配置说明。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1万+

【Leetcode】Maximum Product Subarray

题目链接:https://leetcode.com/problems/maximum-product-subarray/ 题目: Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, give

业精于勤,荒于嬉 3314

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Leetcode:Maximum Product Subarray

连接:https://leetcode.com/problems/maximum-product-subarray/#/description题意:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given

zhumingyuan111的博客 300

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Leetcode152 Maximum Product Subarray python

Leetcode152 Maximum Product Subarray题目解法1:brutal force解法2:同时记录最小和最大值解法3:分类讨论解法4:双向动规 题目 Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which...

qq_37821701的博客 310

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Leetcode: 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

给永远比拿愉快 1231

leetcode Maximum Product Subarray

之前好像做过这样的,以前是加法,现在是乘法。 一开始我也傻逼得用n方的试了下,肯定是TLE的。 那显然就是可以O(n)解决了 用两个dp数组,一个存最大值,一个存最小值,因为可能是负数再乘以负数就很大了,所以每次更新需要借助最小值一同更新最大值。最后遍历一边dp大的数组就有答案了。 class Solution { public: int maxProduct(i...

183

每周LeetCode算法题(十三)152. Maximum Product Subarray

每周LeetCode算法题(十三)题目: 152. 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,

JacKnights的博客 318

LeetCode:Maximum Product Subarray

Maximum Product Subarray Total Accepted:48973Total Submissions:231867Difficulty:Medium Find the contiguous subarray within an array (containing at least one number) which has the

walker lee 653

[LeetCode] Maximum Product Subarray 解题思路

问题:求解乘积最大的连续子数组。这道和 Maximum Subarray相似。 将原问题转换为:第一步,求 n 个分别以 i ( 0 -> n-1 ) 结尾的 乘积最大(乘积最小)的连续子数组。第二步,找出第一步中最大值的便是原问题的解。

723

【LeetCode】#152乘积最大子序列(Maximum Product Subarray)

【LeetCode】#152乘积最大子序列(Maximum Product Subarray) 题目描述 给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数)。 示例 示例 1: 输入: [2,3,-2,4] 输出: 6 解释: 子数组 [2,3] 有最大乘积 6。 示例 2: 输入: [-2,0,-1] 输出: 0 解释: 结果不能为 2, 因为 [-2,-1...

weixin_43858604的博客 177

LeetCode Maximum Subarray Maximum Product Subarray DP问题

Maximum Subarray 题目: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the cont

Mike_CSU的博客 498

[LeetCode] Maximum Product Subarray的4种解法

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 larges

┅☆心随风飞 7206

Leetcode之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 lar

漫漫学习路 421
上一篇: LeetCode Maximum Subarray
下一篇: LeetCode Maximal Square
Dylan_Java_NYC
博客等级 码龄11年 1粉丝 134原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值