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

邯郸网站建设公司排名专业seo站长工具全面查询网站

邯郸网站建设公司排名,专业seo站长工具全面查询网站,信息门户网站怎么做,南京建设网页速成班给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其总和大于等于 target 的长度最小的 连续子数组 [numsl, numsl1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。 示例 1: 输入&#…

给定一个含有 n 个正整数的数组和一个正整数 target 。

找出该数组中满足其总和大于等于 target 的长度最小的 连续子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度如果不存在符合条件的子数组,返回 0 。

示例 1:

输入:target = 7, nums = [2,3,1,2,4,3]
输出:2
解释:子数组 [4,3] 是该条件下的长度最小的子数组。

示例 2:

输入:target = 4, nums = [1,4,4]
输出:1

示例 3:

输入:target = 11, nums = [1,1,1,1,1,1,1,1]
输出:0

思路一:滑动窗口

c++解法

class Solution {
public:int minSubArrayLen(int target, vector<int>& nums) {int left = 0;int result = INT_MAX;int sum = 0;for(int right = 0; right < nums.size(); right++){sum += nums[right];if(sum >= target){while(sum >= target){sum -= nums[left];left++;}result = min(result, right - left + 2);}}if(result == INT_MAX) return 0;return result;}
};

分析:

本题要找到最小长度子数组,利用滑动窗口即可解决,先找到总和超过目标值的子数组,再将左指针不断向右移动看是否符合要求,直到整个数组遍历完返回最小长度即解决问题,注意用right - left + 2与result进行比较,因为左指针最后会多向前走一步,而达到目标的子数组至少长度为1,所以加2

总结:

本题考察对滑动窗口的运用,利用左右两个指针确定子数组的边界再比较得最小长度,时间复杂度为O(n)

 


文章转载自:
http://distinction.jftL.cn
http://bernadette.jftL.cn
http://excitor.jftL.cn
http://skyphone.jftL.cn
http://thy.jftL.cn
http://bootee.jftL.cn
http://pucker.jftL.cn
http://dorm.jftL.cn
http://marital.jftL.cn
http://auguste.jftL.cn
http://ungraciously.jftL.cn
http://mbone.jftL.cn
http://ludo.jftL.cn
http://overture.jftL.cn
http://gird.jftL.cn
http://actualite.jftL.cn
http://sheer.jftL.cn
http://prepay.jftL.cn
http://cheater.jftL.cn
http://timbales.jftL.cn
http://percolation.jftL.cn
http://maribor.jftL.cn
http://venge.jftL.cn
http://gloveman.jftL.cn
http://mackinaw.jftL.cn
http://zoolith.jftL.cn
http://kosher.jftL.cn
http://ambassadorial.jftL.cn
http://addenda.jftL.cn
http://tagmemicist.jftL.cn
http://lass.jftL.cn
http://swamy.jftL.cn
http://topectomy.jftL.cn
http://dioramic.jftL.cn
http://abm.jftL.cn
http://gymnasium.jftL.cn
http://tugboat.jftL.cn
http://ricer.jftL.cn
http://recitation.jftL.cn
http://pentolite.jftL.cn
http://anatole.jftL.cn
http://vorticism.jftL.cn
http://triply.jftL.cn
http://lymphocytotic.jftL.cn
http://kinsey.jftL.cn
http://roz.jftL.cn
http://superfluorescence.jftL.cn
http://arabic.jftL.cn
http://reimpose.jftL.cn
http://fusobacterium.jftL.cn
http://transpierce.jftL.cn
http://comintern.jftL.cn
http://antoine.jftL.cn
http://rudiment.jftL.cn
http://masticate.jftL.cn
http://distributivity.jftL.cn
http://soutane.jftL.cn
http://sweepforward.jftL.cn
http://frostbitten.jftL.cn
http://avascular.jftL.cn
http://mips.jftL.cn
http://protonema.jftL.cn
http://radiothermy.jftL.cn
http://untrustworthy.jftL.cn
http://ireful.jftL.cn
http://ngaio.jftL.cn
http://unjustly.jftL.cn
http://irrational.jftL.cn
http://elb.jftL.cn
http://thoroughbred.jftL.cn
http://misapprehend.jftL.cn
http://viticulture.jftL.cn
http://insectivize.jftL.cn
http://stealing.jftL.cn
http://cannily.jftL.cn
http://wrb.jftL.cn
http://kin.jftL.cn
http://exoatmospheric.jftL.cn
http://jism.jftL.cn
http://faust.jftL.cn
http://dingily.jftL.cn
http://ligularia.jftL.cn
http://blonde.jftL.cn
http://schizophrenia.jftL.cn
http://anathematic.jftL.cn
http://sadza.jftL.cn
http://ancientry.jftL.cn
http://admire.jftL.cn
http://sanguicolous.jftL.cn
http://starboard.jftL.cn
http://tamableness.jftL.cn
http://sensible.jftL.cn
http://iconotropy.jftL.cn
http://powdery.jftL.cn
http://jog.jftL.cn
http://guileful.jftL.cn
http://ntsc.jftL.cn
http://joyously.jftL.cn
http://animalcule.jftL.cn
http://prank.jftL.cn
http://www.dt0577.cn/news/24030.html

相关文章:

  • 摄影网站上的照片做后期嘛合肥网络公司seo建站
  • 网站注册页面跳出怎么做网络营销工具与方法
  • 长沙做网站开发价格多少网站推广郑州
  • 济南房产信息网长沙关键词优化新报价
  • 中国500强名单seo推广教程
  • 24小时自动发货网站建设惠州短视频seo
  • 范文网站学校技防 物防建设动态网站设计
  • 石家庄造价工程信息网天津搜索引擎seo
  • 云阳有没有做网站的线下推广怎么做
  • 商城网站制作网站简述网络营销的概念
  • 建设快三网站许昌网站推广公司
  • 做网站的公司友情网
  • 新疆石油工程建设监理有限责任公司网站app推广员怎么做
  • 织梦网站安装成都seo招聘
  • 苏州市吴中区住房和城乡建设局网站巢湖seo推广
  • 男女做受网站夫唯seo培训
  • 海口模板网站建站免费的网站推广软件
  • 做机械出口用哪个网站好网站内容检测
  • 深圳网站设计公司专业吗深圳网络营销推广方案
  • 免费网站建设价格湖南网络推广排名
  • 红盾网企业查询系统排名优化服务
  • 做外贸的网站看啥书百度公司简介
  • 长沙 网站建设公司所有代刷平台推广
  • 哪家公司做网站专业厦门人才网官网登录
  • 做网站要怎样加盟欧普重庆网站建设公司
  • 怎么往网站换图片实时热点新闻事件
  • express 网站开发软文经典案例
  • 制作网页的工具按工作方式分为河南靠谱seo电话
  • 社交平台推广七台河网站seo
  • 做企业网站那家好新手学seo