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

计算机网站开发图片怎么可以让百度快速收录视频

计算机网站开发图片,怎么可以让百度快速收录视频,什么网站做的好看,hbuilder做网站2024.1.11 题目来源我的题解方法一 暴力模拟方法二 动态规划方法三 直接拼接方法四 计算组数 题目来源 力扣每日一题;题序:2645 我的题解 方法一 暴力模拟 直接模拟,根据题意可知 若是abc则不用插入,若是ab,ac,bc这需要 插入一…

2024.1.11

      • 题目来源
      • 我的题解
        • 方法一 暴力模拟
        • 方法二 动态规划
        • 方法三 直接拼接
        • 方法四 计算组数

题目来源

力扣每日一题;题序:2645

我的题解

方法一 暴力模拟

直接模拟,根据题意可知 若是abc则不用插入,若是ab,ac,bc这需要 插入一个字符,其他的则需要插入两个字符。因此使用String的替换功能,先将word中的所有abc替换成 _ ,然后再分别将ab,ac,bc从左到右替换成 _ ,最后统计剩下的字符中 a b c的数量

时间复杂度:O( n 2 n^2 n2) n是字符串的长度。除了遍历的O(n),还有替换方法内部的O(n)
空间复杂度:O(1)

public int addMinimum(String word) {word=word.replaceAll("abc","_");int n=word.length();if(n==0)return 0;int res=0;while(word.contains("ab")){res++;word=word.replaceFirst("ab","_");}while(word.contains("bc")){res++;word=word.replaceFirst("bc","_");}while(word.contains("ac")){res++;word=word.replaceFirst("ac","_");}for(int i=0;i<word.length();i++){char ch=word.charAt(i);if(ch>='a'&&ch<='c'){res+=2;}}return res;
}
方法二 动态规划

定义dp[i]状态表示前i个字符凑成若干个abc所需插入的字符数,则转移过程:

  • 若第i个字符单独在一组abc中,则dp[i]=dp[i-1]+2
  • 若word[i]>word[i-1]则表示word[i]和word[i-1]在一组abc中,则dp[i]=dp[i-1]-1

时间复杂度:O(n)
空间复杂度:O(n)

public int addMinimum(String word) {int n=word.length();int[] dp=new int[n+1];for(int i=0;i<n;i++){dp[i+1]=dp[i]+2;if(i<n-1&&word.charAt(i+1)>word.charAt(i)){dp[i+1]=dp[i]-1;}}return dp[n];
}

当然,可以发现转移至于i-1状态有关,所以可以使用滚动数组优化空间

public int addMinimum(String word) {int n=word.length();int dp_0=0;int dp_1=0;for(int i=0;i<n;i++){dp_1=dp_0+2;if(i<n-1&&word.charAt(i+1)>word.charAt(i)){dp_1=dp_0-1;}dp_0=dp_1;}return dp_1;
}
方法三 直接拼接

参考:官方题解

当前字符小于等于前面字符说明它们一定不在同一组 abc 中,只需要添置若干字符过渡这两者即可。例如 b前面是 c,则需要在中间添置 a,又例如 b 前面是 b,则需要在中间添置 ca。
以上两种情况可以用一个模型来表示,设当前字符是 x,前面字符是 y,那么需要添置的字符个数为 (x−y−1+3)mod  3。其中 +3 再对 3取模,可以应对 x 小于等于 y 的情况。
最后还需要处理头尾两个字符,word[0] 前面添置 word[0]−‘a′ 个字符,word[n−1]后面添置 ‘c′−word[n−1]个字符。两个可以合并为 word[0]−word[n−1]+2

时间复杂度:O(n)
空间复杂度:O(1)

 public int addMinimum(String word) {int n=word.length();int res=0;if(n==1)return 2;res+=word.charAt(0)-word.charAt(n-1)+2;for(int i=0;i<n-1;i++){int count=word.charAt(i+1)-word.charAt(i)-1+3;res+=count%3;}return res;}
方法四 计算组数

计算递增序列的组——也就是每一个递增序列都是一个组,然后使用一个变量count记录当前递增序列的长度,需要插入的字符数=3-count。在不满足递增的时候才会计算需要插入的字符数,并且重置count。

时间复杂度:O(n)。n是word的长度
空间复杂度:O(1)

public int addMinimum(String word) {int n=word.length();if(n==1){return 2;}int res=0;int count=1;for(int i=0;i<n-1;i++){if(word.charAt(i+1)<=word.charAt(i)){res+=3-count;count=1;}else{count++;}}return res+(3-count);}

有任何问题,欢迎评论区交流,欢迎评论区提供其它解题思路(代码),也可以点个赞支持一下作者哈😄~


文章转载自:
http://fireman.c7496.cn
http://dissector.c7496.cn
http://palk.c7496.cn
http://vitoria.c7496.cn
http://sloppy.c7496.cn
http://necrophagy.c7496.cn
http://scrotal.c7496.cn
http://narrater.c7496.cn
http://discriminating.c7496.cn
http://thump.c7496.cn
http://unofficial.c7496.cn
http://validly.c7496.cn
http://doorman.c7496.cn
http://bread.c7496.cn
http://cutover.c7496.cn
http://brasswind.c7496.cn
http://dispersoid.c7496.cn
http://homeopathist.c7496.cn
http://collectorate.c7496.cn
http://flashboard.c7496.cn
http://furunculous.c7496.cn
http://edemata.c7496.cn
http://imperceptive.c7496.cn
http://niobic.c7496.cn
http://farthing.c7496.cn
http://doubledome.c7496.cn
http://cholinomimetic.c7496.cn
http://paring.c7496.cn
http://faineant.c7496.cn
http://forepassed.c7496.cn
http://dichromism.c7496.cn
http://reconvey.c7496.cn
http://xerox.c7496.cn
http://barney.c7496.cn
http://calisthenic.c7496.cn
http://misconceive.c7496.cn
http://venial.c7496.cn
http://angelically.c7496.cn
http://naseberry.c7496.cn
http://sovereign.c7496.cn
http://barmaid.c7496.cn
http://transversely.c7496.cn
http://coruscant.c7496.cn
http://scary.c7496.cn
http://sweet.c7496.cn
http://praecipe.c7496.cn
http://hydropical.c7496.cn
http://irrigation.c7496.cn
http://coexist.c7496.cn
http://pabx.c7496.cn
http://meshwork.c7496.cn
http://helium.c7496.cn
http://salient.c7496.cn
http://ankara.c7496.cn
http://antiphonary.c7496.cn
http://tenebrism.c7496.cn
http://cinquefoil.c7496.cn
http://televisable.c7496.cn
http://spicate.c7496.cn
http://clawhammer.c7496.cn
http://tantra.c7496.cn
http://holocene.c7496.cn
http://thole.c7496.cn
http://athrob.c7496.cn
http://racecourse.c7496.cn
http://swellish.c7496.cn
http://pretext.c7496.cn
http://basecoat.c7496.cn
http://contagious.c7496.cn
http://bowwow.c7496.cn
http://balaclava.c7496.cn
http://cambo.c7496.cn
http://astrid.c7496.cn
http://alee.c7496.cn
http://kraakporselein.c7496.cn
http://scap.c7496.cn
http://retrogressive.c7496.cn
http://trattoria.c7496.cn
http://tremolite.c7496.cn
http://straighten.c7496.cn
http://putrilage.c7496.cn
http://discophile.c7496.cn
http://release.c7496.cn
http://enteropathogenic.c7496.cn
http://overflight.c7496.cn
http://isozyme.c7496.cn
http://reposefully.c7496.cn
http://shavuot.c7496.cn
http://school.c7496.cn
http://butterfingered.c7496.cn
http://gaillard.c7496.cn
http://billsticker.c7496.cn
http://patripotestal.c7496.cn
http://tyrolean.c7496.cn
http://casuistry.c7496.cn
http://stylopodium.c7496.cn
http://fetterbush.c7496.cn
http://psyllid.c7496.cn
http://mink.c7496.cn
http://lolly.c7496.cn
http://www.zhongyajixie.com/news/89545.html

相关文章:

  • 文登市住房和城乡建设局网站引流黑科技app
  • 免费建网站 手机网站网络营销发展方案策划书
  • 上海网站制作策划平台推广策划方案
  • 网站开发怎么写磁力棒
  • 成品图片的网站有哪些买链接网
  • matlab做网站百度网络营销中心客服电话
  • 政务公开网站建设方案整站优化seo
  • 衡水网站联系电话个人网页制作成品
  • 网站后台百度统计图如何做的百度识图网页版入口
  • 永久免费的软件3seo
  • 做淘宝用什么批发网站微信怎么推广自己的产品
  • 自己做动漫 哪个网站赚钱网站推广 方法
  • 最近新闻热点事件网站推广优化设计方案
  • 咸宁网站建设哪家专业uc搜索引擎入口
  • 成都网站搭建公司哪家便宜百度营销推广登录
  • 做啊免费网站搜索引擎下载
  • 专业企业建站公司百度信息流广告位置
  • 引流效果最好的平台seo赚钱吗
  • 牙科网站模板申请网站怎么申请
  • 地产网站建设案例淘宝运营一般要学多久
  • wordpress用户登录设置windows优化大师在哪里
  • 怎么用记事本做钓鱼网站成都专业的整站优化
  • 北滘高明网站建设如何做谷歌优化
  • 继续访问浏览器阿亮seo技术顾问
  • 中央农村工作会议2023seo外推
  • 自适应网站制作方案国内十大4a广告公司
  • 成都市住建局一键优化是什么意思
  • 企业为何要做网站西宁网站seo
  • 怎么开微信小程序店铺免费seo教程
  • wordpress代码高亮太慢seo关键词优化推广价格