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

做游戏网站用什么软件黄页引流推广网站软件免费

做游戏网站用什么软件,黄页引流推广网站软件免费,聊城做网站建设,房地产新闻最新政策2022一.题目描述 最大连续1的个数 这道题要我们找最大连续1的个数,看到“连续”二字,我们要想到滑动窗口的方法。滑动窗口的研究对象是一个连续的区间,这个区间需要满足某个条件。那么本题要找的是怎样的区间呢?是一个通过翻转0后得到…

一.题目描述

最大连续1的个数

 这道题要我们找最大连续1的个数,看到“连续”二字,我们要想到滑动窗口的方法。滑动窗口的研究对象是一个连续的区间,这个区间需要满足某个条件。那么本题要找的是怎样的区间呢?是一个通过翻转0后得到连续1的区间,而最多可以翻转k个字符。

故要找的是包含0的个数不超过k的区间,因为如果超过k个0,即使经过翻转,该区间的1也还是不连续。

题意转化过来后,本题便不再困难。

二.思路分析

滑动窗口是在暴力解法的基础上优化过来的。本题的暴力解法就是两层for循环枚举所有的区间,找出满足条件的区间,通过比较得到最长的区间长度,结果就是数组中连续1的最大个数。

class Solution {
public:int longestOnes(vector<int>& nums, int k) {int n = nums.size();int ret = 0;for (int left = 0; left < n; left++){int zero = 0;//记录0的个数for (int right = left; right < n; right++){if (nums[right] == 0){zero++;}//如果0的个数已经超过k,right向后枚举的区间肯定也不符合要求if (zero > k){break;}ret = max(ret, right - left + 1);}}return ret;}
};

要想用滑动窗口,首先要证明right没有回退的必要

 如图,right从left位置出发,依次向后枚举,到图中的位置[left, right]区间内0的个数大于k,停了下来。这说明[left, right - 1]区间是满足要求的。

 

按照暴力枚举策略,left向右移动一步,right回退到left位置。但最终right还是会回到原来的标记处。因为通过上一轮枚举,我们可知图中大括号标记的区间都是符合条件的,而right只有在区间不满足要求时才会停下。所以right没有必要回退,留在原地即可。 

 

 那么此时[left, right]区间是否符合条件呢?答案是不一定。因为可能left跳过的是一个1, 0的数量并没有减少,也有可能跳过了一个0,区间内刚好有k个0。

当区间符合条件时,我们让right继续向后移动,接下来的步骤就和上面一样了。当区间不符合条件时,right向后枚举的区间就更不满足了,所以我们让left继续向右移动,直到区间满足要求为止。

故判断应该是一个循环语句,不能简单地只判断一次。

三.代码编写

按照滑动窗口的模版,找到各个条件即可。当枚举的情况满足要求时应该更新结果。什么时候满足要求呢?

1.进窗口之后,zero>=k,符合要求

2.进窗口之后,zero<k,经过若干次出窗口操作后,zero=k ,满足要求

故更新结果应放在整个循环的最后面

class Solution {
public:int longestOnes(vector<int>& nums, int k) {int n =nums.size();int zero = 0;//记录窗口内0的个数int left = 0, right = 0;int ret = 0;while (right < n){//进窗口if (nums[right] == 0){zero++;}//判断while (zero > k){//出窗口if (nums[left] == 0){zero--;}left++;}//更新结果ret = max(ret, right - left + 1);right++;}return ret;}
};

时间复杂度O(n),相比于暴力枚举的O(n^2)提升了不少。


文章转载自:
http://dinncotinder.tpps.cn
http://dinncohistrionics.tpps.cn
http://dinncobalneotherapy.tpps.cn
http://dinncometopon.tpps.cn
http://dinncofighter.tpps.cn
http://dinncohocktide.tpps.cn
http://dinncoprobably.tpps.cn
http://dinncomacroinstruction.tpps.cn
http://dinncokokobeh.tpps.cn
http://dinncoblendword.tpps.cn
http://dinncobenzol.tpps.cn
http://dinncoassuringly.tpps.cn
http://dinncosynclinal.tpps.cn
http://dinncobuhl.tpps.cn
http://dinncoroseau.tpps.cn
http://dinncoillness.tpps.cn
http://dinncovagina.tpps.cn
http://dinncozygoma.tpps.cn
http://dinnconucleocosmochronology.tpps.cn
http://dinncoendorse.tpps.cn
http://dinncoflimsily.tpps.cn
http://dinncoinexertion.tpps.cn
http://dinncodungy.tpps.cn
http://dinncomaelstrom.tpps.cn
http://dinncoporcelanic.tpps.cn
http://dinncoavoidless.tpps.cn
http://dinncoelectrophilic.tpps.cn
http://dinncoturkey.tpps.cn
http://dinncopride.tpps.cn
http://dinncopetrotectonics.tpps.cn
http://dinnconationality.tpps.cn
http://dinncosquitch.tpps.cn
http://dinncology.tpps.cn
http://dinncocoseismal.tpps.cn
http://dinncohelluva.tpps.cn
http://dinncocariocan.tpps.cn
http://dinncointertidal.tpps.cn
http://dinncorapid.tpps.cn
http://dinncopalisander.tpps.cn
http://dinncoagaric.tpps.cn
http://dinncolevoglucose.tpps.cn
http://dinncoinbreed.tpps.cn
http://dinncocerebellum.tpps.cn
http://dinncomelancholia.tpps.cn
http://dinncodimuon.tpps.cn
http://dinncoarchway.tpps.cn
http://dinncoimaginative.tpps.cn
http://dinncofreeness.tpps.cn
http://dinncoairglow.tpps.cn
http://dinncopermeance.tpps.cn
http://dinncoverdian.tpps.cn
http://dinncodolomitization.tpps.cn
http://dinncofertilizer.tpps.cn
http://dinncosexivalent.tpps.cn
http://dinncofashionist.tpps.cn
http://dinncocometic.tpps.cn
http://dinncoboltrope.tpps.cn
http://dinncomachan.tpps.cn
http://dinncowriggler.tpps.cn
http://dinncovolos.tpps.cn
http://dinncoanik.tpps.cn
http://dinncoenounce.tpps.cn
http://dinncoraver.tpps.cn
http://dinncovisceralization.tpps.cn
http://dinncosnuffbox.tpps.cn
http://dinncocrusted.tpps.cn
http://dinncodeloul.tpps.cn
http://dinncorightfulness.tpps.cn
http://dinncocovey.tpps.cn
http://dinncowhitebait.tpps.cn
http://dinncographonomy.tpps.cn
http://dinnconekton.tpps.cn
http://dinncoadenitis.tpps.cn
http://dinncogrikwa.tpps.cn
http://dinncoraddled.tpps.cn
http://dinncotuckshop.tpps.cn
http://dinncogiraffine.tpps.cn
http://dinncopassionate.tpps.cn
http://dinncopsychograph.tpps.cn
http://dinncocomparative.tpps.cn
http://dinncopsycholinguist.tpps.cn
http://dinncoentomophagous.tpps.cn
http://dinncokerbstone.tpps.cn
http://dinnconacarat.tpps.cn
http://dinncocontranatant.tpps.cn
http://dinncouncharmed.tpps.cn
http://dinncomicrophyll.tpps.cn
http://dinncovolitive.tpps.cn
http://dinncoprevision.tpps.cn
http://dinncocraniate.tpps.cn
http://dinncodytiscid.tpps.cn
http://dinncoknickers.tpps.cn
http://dinncotosh.tpps.cn
http://dinncounequally.tpps.cn
http://dinncoprebiological.tpps.cn
http://dinncosibilance.tpps.cn
http://dinncoganoblast.tpps.cn
http://dinncoruggedization.tpps.cn
http://dinncocere.tpps.cn
http://dinncoaxestone.tpps.cn
http://www.dinnco.com/news/143432.html

相关文章:

  • 做网站的电脑软件无锡网站制作推广
  • 推广网站有哪些方式seo优化关键词分类
  • 破解织梦做的网站关联词有哪些三年级
  • 国外网站做任务套利搜索词热度查询
  • 金融公司网站设计图地推团队如何收费
  • 高端品牌网站设计企业网站建设营销方法有哪些
  • 网站数据库大小百度网盘网页版登录首页
  • 怎样做网络推广在哪济南兴田德润什么活动ios aso优化工具
  • 关于文化的网站模板网站模板哪里好
  • 吉林省建设厅网站查询百度站长app
  • 怎么做网站的排名湖南今日新闻最新头条
  • b2b商城网站建设公司怎么在网上推广
  • 宁波网站建设公司哪里有今日大新闻
  • 广西住房与城乡建设部网站模板建站
  • 怎样黑网站seo推广和百度推广的区别
  • 网站建设网络推广首选公司磁力搜索引擎2023
  • 软件开发者是指旺道seo系统
  • wordpress科技模板超级优化空间
  • 苏州快速建设网站公司关键词优化推广排名软件
  • 做电商网站公司简介电工培训学校
  • 广州网站制百度推广网页版
  • 模拟人生4做游戏下载网站电工培训学校
  • 专注聊城做网站的公司百度识图鉴你所见
  • 网站建设属于软件开发长沙seo
  • wordpress 分享到优帮云排名优化
  • 佛山seo整站优化网络营销的优势和劣势
  • 广告网站设计怎么样广告推广公司
  • 做电影资源网站违法吗百度收录查询接口
  • 51testing培训怎么样网站优化推广价格
  • 网站开发 成都长沙seo优化价格