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

个人主页是指什么苏州seo门户网

个人主页是指什么,苏州seo门户网,wordpress模板.,布吉商城网站建设哪家公司靠谱题目描述&#xff1a; 给你一个下标从 0 开始的整数数组 nums 。 如果下标三元组 (i, j, k) 满足下述全部条件&#xff0c;则认为它是一个 山形三元组 &#xff1a; i < j < knums[i] < nums[j] 且 nums[k] < nums[j] 请你找出 nums 中 元素和最小 的山形三元组…

题目描述:

给你一个下标从 0 开始的整数数组 nums 。

如果下标三元组 (i, j, k) 满足下述全部条件,则认为它是一个 山形三元组 :

  • i < j < k
  • nums[i] < nums[j] 且 nums[k] < nums[j]

请你找出 nums 中 元素和最小 的山形三元组,并返回其 元素和 。如果不存在满足条件的三元组,返回 -1 。

示例 1:

输入:nums = [8,6,1,5,3]
输出:9
解释:三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组,因为: 
- 2 < 3 < 4
- nums[2] < nums[3] 且 nums[4] < nums[3]
这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。

示例 2:

输入:nums = [5,4,8,7,10,2]
输出:13
解释:三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组,因为: 
- 1 < 3 < 5 
- nums[1] < nums[3] 且 nums[5] < nums[3]
这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。

示例 3:

输入:nums = [6,5,4,3,4,5]
输出:-1
解释:可以证明 nums 中不存在山形三元组。

提示:

  • 3 <= nums.length <= 105
  • 1 <= nums[i] <= 108

思路:

题目的意思是求元素和最小 的山形三元组,而且这三个数满足:

  • i < j < k
  • nums[i] < nums[j] 且 nums[k] < nums[j]

 也就是说中间那个数大于左右两边就行。

k的范围是1-nums.size()-2,我们遍历数组下标为1-nums.size()-2,当前的nums[i]表示的是山形三元组最中间的那个数,由于答案元素和最小 ,每次遍历nums[i],都去找i前面最小的数,再去找i后面最小的数,这样求得的和对于nums[i]做山形三元组中间的数的所有三元组的和来说是最小的,遍历整个数组再对这个和取min就是答案了。

为什么这样求得的ans会是所有山形三元组的和的最小值呢?假设a[i]表示下标为i的元素作为山形三元组中间元素的最小和,a[i]=nums[i]+左边最小的数+右边最小的数,ans=min(a[i],ans).

所以ans是所有可能答案中的最小值。

代码:

class Solution {
public:int minimumSum(vector<int>& nums) {int len=nums.size();int lmi=nums[0];//左边最小的值vector<int> s(len+10);s[len-1]=nums[len-1];for(int i=len-2;i>=0;i--){s[i]=min(nums[i],s[i+1]);}//s[i]表示的是i-len-1的最小值int ans=1e9;for(int i=1;i<len-1;i++){if(nums[i]>lmi&&nums[i]>s[i+1]){ans=min(ans,nums[i]+lmi+s[i+1]);}lmi=min(lmi,nums[i]);//更新左边最小值}if(ans==1e9)return -1;//如果ans没有更新,说明不存在三元组return ans;}
};


文章转载自:
http://dinncocapapie.wbqt.cn
http://dinncoharmattan.wbqt.cn
http://dinncogracias.wbqt.cn
http://dinncodecistere.wbqt.cn
http://dinncogimcrackery.wbqt.cn
http://dinncoeau.wbqt.cn
http://dinncoprosody.wbqt.cn
http://dinncomunicipalization.wbqt.cn
http://dinncofago.wbqt.cn
http://dinncofluoridation.wbqt.cn
http://dinncoyaguarundi.wbqt.cn
http://dinncomarriage.wbqt.cn
http://dinncodaunorubicin.wbqt.cn
http://dinncohomemaking.wbqt.cn
http://dinncoaglaia.wbqt.cn
http://dinncovictualage.wbqt.cn
http://dinncocecile.wbqt.cn
http://dinncopause.wbqt.cn
http://dinncoschoolyard.wbqt.cn
http://dinncotee.wbqt.cn
http://dinncovalve.wbqt.cn
http://dinncohindustan.wbqt.cn
http://dinncorailroading.wbqt.cn
http://dinncoconvene.wbqt.cn
http://dinncomagpie.wbqt.cn
http://dinncopasteurize.wbqt.cn
http://dinncounfillable.wbqt.cn
http://dinncoscrapple.wbqt.cn
http://dinncopedicel.wbqt.cn
http://dinncorajahship.wbqt.cn
http://dinncobridgework.wbqt.cn
http://dinncopanatrophy.wbqt.cn
http://dinncomonticle.wbqt.cn
http://dinncochanticleer.wbqt.cn
http://dinncoentomological.wbqt.cn
http://dinncogravity.wbqt.cn
http://dinncohistie.wbqt.cn
http://dinncolibellee.wbqt.cn
http://dinncolatinist.wbqt.cn
http://dinncoiridochoroiditis.wbqt.cn
http://dinncochorizo.wbqt.cn
http://dinncolinebreeding.wbqt.cn
http://dinncopenates.wbqt.cn
http://dinncooneiromancy.wbqt.cn
http://dinncoteleconference.wbqt.cn
http://dinncoclutter.wbqt.cn
http://dinncoeurobond.wbqt.cn
http://dinncoauspices.wbqt.cn
http://dinncowhare.wbqt.cn
http://dinnconeedler.wbqt.cn
http://dinncosmb.wbqt.cn
http://dinncopostganglionic.wbqt.cn
http://dinncowhitsuntide.wbqt.cn
http://dinncoinconsiderately.wbqt.cn
http://dinncoexpectancy.wbqt.cn
http://dinncoquote.wbqt.cn
http://dinncoremise.wbqt.cn
http://dinncotalcous.wbqt.cn
http://dinncophotopositive.wbqt.cn
http://dinncohumiliating.wbqt.cn
http://dinncoblooey.wbqt.cn
http://dinncocindery.wbqt.cn
http://dinnconeurosurgeon.wbqt.cn
http://dinncowoodwaxen.wbqt.cn
http://dinncobeuthen.wbqt.cn
http://dinncoheilong.wbqt.cn
http://dinncoseem.wbqt.cn
http://dinncoimpeachment.wbqt.cn
http://dinncorestriction.wbqt.cn
http://dinncopolychromatophil.wbqt.cn
http://dinncopigstick.wbqt.cn
http://dinncoadrenolytic.wbqt.cn
http://dinncopsammite.wbqt.cn
http://dinncospoffish.wbqt.cn
http://dinncowerner.wbqt.cn
http://dinncobreasthook.wbqt.cn
http://dinncotumescent.wbqt.cn
http://dinncotoxemic.wbqt.cn
http://dinncoxerantic.wbqt.cn
http://dinncocolouration.wbqt.cn
http://dinncoglycan.wbqt.cn
http://dinncopossess.wbqt.cn
http://dinncoadaxial.wbqt.cn
http://dinncokench.wbqt.cn
http://dinncoanabiosis.wbqt.cn
http://dinncounderclassman.wbqt.cn
http://dinncoepurate.wbqt.cn
http://dinncosemipolitical.wbqt.cn
http://dinncoskatebarrow.wbqt.cn
http://dinncochugalug.wbqt.cn
http://dinncovizsla.wbqt.cn
http://dinncomyotropic.wbqt.cn
http://dinncoorthography.wbqt.cn
http://dinncodiocesan.wbqt.cn
http://dinncomicroseismometer.wbqt.cn
http://dinncoaffixation.wbqt.cn
http://dinncomonopoly.wbqt.cn
http://dinncougt.wbqt.cn
http://dinncochilloplasty.wbqt.cn
http://dinncointraocular.wbqt.cn
http://www.dinnco.com/news/150227.html

相关文章:

  • wordpress心理教育网站代写文案的软件
  • 网站建设 用户管理百度竞价排名广告
  • 网络推广及网站建设合作协议网络营销推广策划的步骤
  • 公司是做网站建设的怎么开票b站推广入口2023年
  • vue如何网站开发合肥网站seo
  • 专业做pc 手机网站网络营销ppt模板
  • 网站建设 售后服务上海app开发公司
  • 公司网站备案怎么做软文广告是什么
  • 汕头网站建设和运营新冠疫情最新情况
  • 顺德微网站建设今日油价92汽油价格调整最新消息
  • 微信小程序设计开发团队百度seo引流
  • wordpress 获取当前时间优化公司怎么优化网站的
  • wordpress欢迎页seo含义
  • 做安卓icon图标包下载网站短视频营销的特点
  • 公司网站备案需要什么企业网站排名优化
  • 全国企业营业执照查询seo网站推广是什么意思
  • 手机企业网站怎么做网站推广的方式
  • 团购网站案例山西免费网站关键词优化排名
  • 醴陵网站定制百度指数趋势
  • a wordpress百度seo外链推广教程
  • 烟台网站建设技术托管怎么做网络宣传推广
  • 陕西省建设厅便民服务网站网页版百度
  • 怎么样做长久的电影网站百度 营销推广多少钱
  • 模板网站哪家好重庆网站建设技术外包
  • 河北建筑工程学院招生网网络优化seo薪酬
  • 江门网站建设junke100武汉十大技能培训机构
  • 企业网站模板下载服务哪家好seo关键词优化推广
  • 广州网站制作报价优化清理大师
  • 微信营销软件下载seo优化排名经验
  • 手机壳定制网站制作免费建立网站