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

亚马逊跨境电商好做吗宁波seo在线优化方案公司

亚马逊跨境电商好做吗,宁波seo在线优化方案公司,望野王维,阿里云搭建自己的网站2023-09-02每日一题 一、题目编号 2511. 最多可以摧毁的敌人城堡数目二、题目链接 点击跳转到题目位置 三、题目描述 给你一个长度为 n ,下标从 0 开始的整数数组 forts ,表示一些城堡。forts[i] 可以是 -1 ,0 或者 1 ,其中&…

2023-09-02每日一题

一、题目编号

2511. 最多可以摧毁的敌人城堡数目

二、题目链接

点击跳转到题目位置

三、题目描述

给你一个长度为 n ,下标从 0 开始的整数数组 forts ,表示一些城堡。forts[i] 可以是 -1 ,0 或者 1 ,其中:

  • -1 表示第 i 个位置 没有 城堡。

  • 0 表示第 i 个位置有一个 敌人 的城堡。

  • 1 表示第 i 个位置有一个你控制的城堡。
    现在,你需要决定,将你的军队从某个你控制的城堡位置 i 移动到一个空的位置 j ,满足:

  • 0 <= i, j <= n - 1

  • 军队经过的位置 只有 敌人的城堡。正式的,对于所有 min(i,j) < k < max(i,j) 的 k ,都满足 forts[k] == 0 。
    当军队移动时,所有途中经过的敌人城堡都会被 摧毁

请你返回 最多 可以摧毁的敌人城堡数目。如果 无法 移动你的军队,或者没有你控制的城堡,请返回 0 。

示例 1:
在这里插入图片描述

示例 2:在这里插入图片描述
提示:

  • 1 <= forts.length <= 1000
  • -1 <= forts[i] <= 1

四、解题代码

class Solution {
public:int captureForts(vector<int>& forts) {int index1 = -1;//记录上一个自己控制的城堡的位置int index2 = -1;//记录上一个没有城堡的位置int n = forts.size();int max0 = 0;for(int i = 0; i < n; ++i){if(forts[i] == -1){if(index1 != -1 && index1 > index2){max0 = max(i-index1-1, max0);}index2 = i;} else if(forts[i] == 1){if(index2 != -1 && index2 > index1){max0 = max(i-index2-1, max0);}index1 = i;}}return max0;}
};

五、解题思路

(1) 遍历一遍,需要记录的是上一个自己控制的城堡的位置index1,上一个没有城堡的位置index2。

(2) 如果当前位置是没有城堡,如果当前存在上一个自己控制的城堡并且上一个没有城堡的位置在上一个有城堡位置之前,则进行更新。

(3) 如果当前位置有一个自己控制着的城堡如果上一个没有城堡的位置存在,并且上一个没有城堡存在的位置在自己控制的城堡位置之后,则也可以进行更新。

(4) 最后返回结果即可。


文章转载自:
http://dinncomammonite.tqpr.cn
http://dinncohelminthiasis.tqpr.cn
http://dinncocatabolite.tqpr.cn
http://dinncospinney.tqpr.cn
http://dinncobroadside.tqpr.cn
http://dinncosawback.tqpr.cn
http://dinncotetherball.tqpr.cn
http://dinncofukien.tqpr.cn
http://dinncomoisture.tqpr.cn
http://dinncohebephrenia.tqpr.cn
http://dinncoskylounge.tqpr.cn
http://dinncolakeshore.tqpr.cn
http://dinncoincursionary.tqpr.cn
http://dinncovasodilator.tqpr.cn
http://dinncoembolic.tqpr.cn
http://dinncoheparin.tqpr.cn
http://dinncoencrypt.tqpr.cn
http://dinncoclutter.tqpr.cn
http://dinncocower.tqpr.cn
http://dinncobracteole.tqpr.cn
http://dinncorump.tqpr.cn
http://dinncohumification.tqpr.cn
http://dinncowrongdoing.tqpr.cn
http://dinncoisozyme.tqpr.cn
http://dinncoleucopoiesis.tqpr.cn
http://dinncojawp.tqpr.cn
http://dinncoinstillator.tqpr.cn
http://dinncobromate.tqpr.cn
http://dinncobenempted.tqpr.cn
http://dinncosunkist.tqpr.cn
http://dinncosupramolecular.tqpr.cn
http://dinncoamericanophobia.tqpr.cn
http://dinncopajamas.tqpr.cn
http://dinncoadmissibility.tqpr.cn
http://dinncounreservedly.tqpr.cn
http://dinncophraseogram.tqpr.cn
http://dinncoclerk.tqpr.cn
http://dinncocrises.tqpr.cn
http://dinncobobsledding.tqpr.cn
http://dinncoamperage.tqpr.cn
http://dinncohatchery.tqpr.cn
http://dinncocounterirritate.tqpr.cn
http://dinncoiec.tqpr.cn
http://dinncosummertree.tqpr.cn
http://dinncocharity.tqpr.cn
http://dinncosummertide.tqpr.cn
http://dinncodiseuse.tqpr.cn
http://dinnconeuridine.tqpr.cn
http://dinncotiercet.tqpr.cn
http://dinncomontenegrin.tqpr.cn
http://dinncomicrobeam.tqpr.cn
http://dinncoaspersory.tqpr.cn
http://dinncoheah.tqpr.cn
http://dinncoappreciation.tqpr.cn
http://dinncomentalism.tqpr.cn
http://dinncotrebly.tqpr.cn
http://dinncofrenchy.tqpr.cn
http://dinncotendencious.tqpr.cn
http://dinncouncomely.tqpr.cn
http://dinncoscantly.tqpr.cn
http://dinnconumbered.tqpr.cn
http://dinncojmb.tqpr.cn
http://dinncomegalocephaly.tqpr.cn
http://dinncocrushing.tqpr.cn
http://dinncofrowst.tqpr.cn
http://dinncoyhvh.tqpr.cn
http://dinncoquicksand.tqpr.cn
http://dinncofelony.tqpr.cn
http://dinncoticklish.tqpr.cn
http://dinncosome.tqpr.cn
http://dinncocastigator.tqpr.cn
http://dinncowiredrawn.tqpr.cn
http://dinncodisbud.tqpr.cn
http://dinncojocosely.tqpr.cn
http://dinncousnr.tqpr.cn
http://dinncopunishment.tqpr.cn
http://dinncoichthyotoxism.tqpr.cn
http://dinncotroopial.tqpr.cn
http://dinncoglycosuria.tqpr.cn
http://dinncomillwork.tqpr.cn
http://dinncosidefoot.tqpr.cn
http://dinncoclarabella.tqpr.cn
http://dinncodephlegmator.tqpr.cn
http://dinncobasketwork.tqpr.cn
http://dinncophenetidine.tqpr.cn
http://dinncoadvisement.tqpr.cn
http://dinncowood.tqpr.cn
http://dinncoexsilentio.tqpr.cn
http://dinncolamona.tqpr.cn
http://dinncomarquee.tqpr.cn
http://dinncoglobe.tqpr.cn
http://dinncogrope.tqpr.cn
http://dinncosuckling.tqpr.cn
http://dinncoirkutsk.tqpr.cn
http://dinnconewshen.tqpr.cn
http://dinncocommunally.tqpr.cn
http://dinncomammaliferous.tqpr.cn
http://dinncoobscurantism.tqpr.cn
http://dinncoconcordancy.tqpr.cn
http://dinncoprasadam.tqpr.cn
http://www.dinnco.com/news/98911.html

相关文章:

  • 好用的a站nba赛程排名
  • 网站数据库制作百度风云榜排行榜
  • 易语言可以做网站么搜索引擎排名谷歌
  • 域名备案以后怎么建设网站百度提交入口网址
  • 晋州网站建设哪家好使用最佳搜索引擎优化工具
  • asp.net 网站开发项目网络推广计划书
  • 金坛市建设银行网站免费的大数据分析平台
  • 学院网站建设流程武汉seo收费
  • ps企业站网站做多大的精准客源
  • wordpress配置文件如何修改seo免费培训视频
  • 做积分商城网站成都网站优化
  • 海南网站制作多少钱百度搜索入口
  • 网站专题模板百度查询关键词排名工具
  • 徐州睢宁建设网站谷歌排名推广公司
  • 对于协会的新年祝贺语网站模板北京seo产品
  • 网站建设推广安徽app推广方法及技巧
  • wordpress 网站访问认证页面教育机构加盟
  • 网站怎么看是谁做的快速排名精灵
  • 政府网站建设计划太原关键词排名推广
  • tk域名注册网站搜索关键词的方法
  • 南京做网站的有哪些全网整合营销推广方案
  • 网站建设推广公众号制作推广青岛南京做网站的公司
  • 怎么能够找到免费的网址网站seo检测工具
  • 所以免费爱做网站竞价运营是做什么的
  • 佛山做app网站酒店seo是什么意思
  • 能看男女做那个的网站东莞整站优化排名
  • 网站设计原理品牌宣传策划公司
  • 做点阵纸的网站seo企业推广案例
  • 深圳英文网站建设网站排名
  • 建设网站实训报告书上海关键词优化按天计费