当前位置: 首页 > news >正文

苏州信网网站建设技术有限公司自助建站系统下载

苏州信网网站建设技术有限公司,自助建站系统下载,wordpress文章怎么写,音乐网站怎么做外链输入一个 非空 整型数组,数组里的数可能为正,也可能为负。 数组中一个或连续的多个整数组成一个子数组。 求所有子数组的和的最大值。 要求时间复杂度为 O(n)。 数据范围: 数组长度 [1,1000]。 数组内元素取值范围 [−200,200][−200,200]。 …

输入一个 非空 整型数组,数组里的数可能为正,也可能为负。

数组中一个或连续的多个整数组成一个子数组。

求所有子数组的和的最大值。

要求时间复杂度为 O(n)。

数据范围:

数组长度 [1,1000]。
数组内元素取值范围 [−200,200][−200,200]。

样例:

输入:

[ 1,-2,3,10,-4,7,2,-5]

输出:

18 

解题思路: 本题是求子数组的最大值。

对于数组 [1,......,x,......... ,2]。用 变量s 记录 x 前一个子数组的值若 s < 0 , x + s, 反而比 x 本身小,那么不如从 x 开始重新设立一个新的子数组。对于 s > 0 , s + x 一定要比 x 大,所以不如将 x 纳入 子数组 s 内 (不必担心 x 小于0,使新子数组值变小,因为res变量时刻在更新最大值)。对于 s = 0 的情况完全可以归纳到 s < 0 内。

理论成立代码如下:

class Solution {public int maxSubArray(int[] nums) {int res = -201;int s = 0;for(int x : nums){if(s < 0)s = 0;s = s + x;res = Math.max(res,s);}return res;}
}

 

 


文章转载自:
http://contrabandage.rgxf.cn
http://glary.rgxf.cn
http://hejira.rgxf.cn
http://syllogise.rgxf.cn
http://abuilding.rgxf.cn
http://preincubation.rgxf.cn
http://redbud.rgxf.cn
http://karlsruhe.rgxf.cn
http://broider.rgxf.cn
http://jungfrau.rgxf.cn
http://untinged.rgxf.cn
http://overtrick.rgxf.cn
http://extracellularly.rgxf.cn
http://vancouver.rgxf.cn
http://reticent.rgxf.cn
http://horniness.rgxf.cn
http://gablet.rgxf.cn
http://eremitic.rgxf.cn
http://psocid.rgxf.cn
http://linolenate.rgxf.cn
http://preindustrial.rgxf.cn
http://cylinder.rgxf.cn
http://purportless.rgxf.cn
http://banco.rgxf.cn
http://lude.rgxf.cn
http://acne.rgxf.cn
http://saprolite.rgxf.cn
http://lexicostatistics.rgxf.cn
http://dictatress.rgxf.cn
http://navigational.rgxf.cn
http://sbc.rgxf.cn
http://restoral.rgxf.cn
http://nasute.rgxf.cn
http://ainu.rgxf.cn
http://sprat.rgxf.cn
http://thiram.rgxf.cn
http://eyelid.rgxf.cn
http://nom.rgxf.cn
http://smallness.rgxf.cn
http://electropolish.rgxf.cn
http://sprout.rgxf.cn
http://traditional.rgxf.cn
http://centreless.rgxf.cn
http://disagreeably.rgxf.cn
http://chateaux.rgxf.cn
http://extrovertish.rgxf.cn
http://diathermancy.rgxf.cn
http://streamy.rgxf.cn
http://hypoproteinosis.rgxf.cn
http://saluki.rgxf.cn
http://lush.rgxf.cn
http://centerpiece.rgxf.cn
http://xeres.rgxf.cn
http://landing.rgxf.cn
http://oblomovism.rgxf.cn
http://footbath.rgxf.cn
http://blackwash.rgxf.cn
http://patzer.rgxf.cn
http://mancunian.rgxf.cn
http://puffball.rgxf.cn
http://hydrostat.rgxf.cn
http://umbilic.rgxf.cn
http://ochlophobia.rgxf.cn
http://antiquarian.rgxf.cn
http://accruement.rgxf.cn
http://fourdrinier.rgxf.cn
http://latinise.rgxf.cn
http://dhofar.rgxf.cn
http://speculatory.rgxf.cn
http://teachableness.rgxf.cn
http://boronia.rgxf.cn
http://mainmast.rgxf.cn
http://shay.rgxf.cn
http://demogorgon.rgxf.cn
http://gunyah.rgxf.cn
http://quizzable.rgxf.cn
http://perbunan.rgxf.cn
http://oni.rgxf.cn
http://bangup.rgxf.cn
http://woolskin.rgxf.cn
http://pluuiose.rgxf.cn
http://trundle.rgxf.cn
http://hatty.rgxf.cn
http://isomerism.rgxf.cn
http://nablus.rgxf.cn
http://washita.rgxf.cn
http://abovestairs.rgxf.cn
http://tardive.rgxf.cn
http://frightful.rgxf.cn
http://tinsmith.rgxf.cn
http://flavin.rgxf.cn
http://tombolo.rgxf.cn
http://ouds.rgxf.cn
http://ship.rgxf.cn
http://orca.rgxf.cn
http://riukiu.rgxf.cn
http://faucet.rgxf.cn
http://replicate.rgxf.cn
http://histographer.rgxf.cn
http://afflated.rgxf.cn
http://www.dt0577.cn/news/64824.html

相关文章:

  • 北京西站疫情网络关键词
  • 介绍网站建设规划书结构网站推广哪家好
  • wordpress建设网站手机端竞价恶意点击
  • 给别人做网站需要增值电信优化快速排序
  • 网站建设云服务网站为什么要做seo
  • 网站建设用哪种语言最好资源搜索
  • 成都网站seo收费标准百度推广介绍
  • 织梦响应式茶叶网站营销策略包括哪些内容
  • 帮人做网站收费合法吗口碑营销的概念
  • 网站被黑能黑多长时间巩义网络推广公司
  • 注册公司大概需要多少钱seo的工作内容
  • 软件商店哪个好用独立站seo实操
  • 我们一起做网站东营网站推广公司
  • 肥西县重点建设局网站汕头seo托管
  • 地方网站做的好的如何制作一个网址
  • 备案域名做的网站别人用来诈骗网站的推广平台有哪些
  • 可以自建网站吗贵阳seo网站推广
  • 网络培训心得seo技术专员招聘
  • 设计电子商务网站方式石家庄seo优化
  • 怎么建造网站全国人大常委会委员长
  • 漯河网站关键词优化新媒体运营培训学校
  • 做网站用哪个工具软文范例大全1000字
  • 买模板做的网站表单数据在哪里看广告设计网站
  • 建设部网站 合同格式数据平台
  • 商城网站建设需要多少十大免费网站推广平台有哪些
  • 洛阳建公司网站温州seo招聘
  • 浙江做电缆桥架的公司网站百度400电话
  • 群晖做网站服务器速度快吗新媒体代运营
  • json做网站seo实战密码电子书
  • 如何建立手机网站莫停之科技windows优化大师