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

网站建设需准备什么自己做网站网页归档

网站建设需准备什么,自己做网站网页归档,东莞信息网,公司名字大全列表文章目录 一、题目链接二、参考代码三、所思所悟 一、题目链接 链接: 27. 移除元素 二、参考代码 思路1&#xff1a;找到需要移除的数组元素&#xff0c;将右侧全部元素向左覆盖 int removeElement(vector<int>& nums, int val) {int size nums.size();for (int …

文章目录

  • 一、题目链接
  • 二、参考代码
  • 三、所思所悟


一、题目链接

链接: 27. 移除元素


二、参考代码

思路1:找到需要移除的数组元素,将右侧全部元素向左覆盖

int removeElement(vector<int>& nums, int val) {int size = nums.size();for (int i = 0; i < size; i++) {if (nums[i] == val) {for (int j = i + 1; j < size; j++) {nums[j - 1] = nums[j];}i--;size--;}}return size;}

思路2:使用两个下标来进行遍历,当遇到需要移除的数组元素slow下标不动,fast下标进行前进;当遇到不需要移除数组元素时,将元素放入,并且两个下标进行前进

int removeElement(vector<int>& nums, int val) {int fastindex = 0, slowindex = 0;for (; fastindex < nums.size(); fastindex++) {if (nums[fastindex] != val) {nums[slowindex++] = nums[fastindex];}}return slowindex;}

思路3:使用库函数(后面有库函数具体解释)

int removeElement(vector<int>& nums, int val) {auto newEnd = remove(nums.begin(), nums.end(), val);nums.erase(newEnd, nums.end());return nums.size();}

三、所思所悟

std::remove
定义在 头文件中。它的目的是移除容器中所有等于给定值的元素,但它并不实际从容器中删除这些元素,而是将它们“移动”到容器的末尾,并返回一个指向新逻辑末尾的迭代器。这个新逻辑末尾是第一个应该被移除的元素的位置。
工作原理:

  1. remove 遍历整个容器,寻找等于给定值 val 的元素。
  2. 它不直接删除这些元素,而是将所有不等于 val 的元素向前移动,覆盖那些等于 val 的元素。
  3. 这个过程会一直进行,直到遍历完整个容器。
  4. 最终,所有不等于 val 的元素都会被移动到容器的开始位置,而所有等于 val 的元素都会被移到容器的末尾。
  5. remove 返回一个指向新逻辑末尾的迭代器,即第一个应该被移除的元素的位置。
std::vector<int> v = {1, 2, 3, 4, 3, 3, 5};
auto newEnd = std::remove(v.begin(), v.end(), 3);

在这个例子中,std::remove 会将除了 3 以外的所有元素移动到 v 的开始位置,返回的 newEnd 迭代器会指向第一个 3 的位置。

std::erase
erase 是 std::vector(以及其他容器)的一个成员函数,用于从容器中删除元素或一系列元素。
1.erase(pos,n);
删除从下标pos开始的n个字符,比如erase(0,1)就是删除第一个字符
2.erase(position);
删除postion处的一个字符(position是一个string类型的迭代器)
3.erase(first,last)
删除从first到last之间的字符(first和last都是迭代器)

工作原理:

  1. erase 接受一个或两个迭代器作为参数,这两个迭代器定义了要删除的元素范围。
  2. 如果只提供一个迭代器,erase 会删除该迭代器指向的单个元素。
  3. 如果提供两个迭代器,erase 会删除从第一个迭代器到第二个迭代器(不包括第二个迭代器)之间的所有元素。
  4. erase 会将所有后续的元素向前移动,填补被删除元素留下的空间。
  5. erase 返回一个指向被删除元素之后元素的迭代器。
std::vector<int> v = {1, 2, 3, 4, 5};
v.erase(v.begin() + 2); // 删除第三个元素(值为3)

在这个例子中,std::remove 将所有不等于 3 的元素移动到 v 的开始位置,并返回一个指向第一个 3 的迭代器。然后 erase 删除从这个迭代器到 v.end() 之间的所有元素,包括所有的 3。最终 v 变为 {1, 2, 4, 5}。


文章转载自:
http://dinncody.wbqt.cn
http://dinncotownship.wbqt.cn
http://dinncocephalalgia.wbqt.cn
http://dinncogynecomorphous.wbqt.cn
http://dinncoprosodeme.wbqt.cn
http://dinncobetweenbrain.wbqt.cn
http://dinncodespondence.wbqt.cn
http://dinncoproprietress.wbqt.cn
http://dinncosnell.wbqt.cn
http://dinncocosmine.wbqt.cn
http://dinncoutriculitis.wbqt.cn
http://dinncodenotative.wbqt.cn
http://dinncocustodial.wbqt.cn
http://dinncorhinolaryngitis.wbqt.cn
http://dinncoirredentism.wbqt.cn
http://dinncolilongwe.wbqt.cn
http://dinncoenrank.wbqt.cn
http://dinncosultriness.wbqt.cn
http://dinncoclasswork.wbqt.cn
http://dinncoundissolved.wbqt.cn
http://dinnconatiform.wbqt.cn
http://dinncoscintillate.wbqt.cn
http://dinncoretook.wbqt.cn
http://dinnconairnshire.wbqt.cn
http://dinncostainer.wbqt.cn
http://dinncochromatid.wbqt.cn
http://dinncocustomable.wbqt.cn
http://dinncoloaded.wbqt.cn
http://dinncombd.wbqt.cn
http://dinncospadable.wbqt.cn
http://dinncothrombokinase.wbqt.cn
http://dinncospoken.wbqt.cn
http://dinncovulpecular.wbqt.cn
http://dinncotranspolar.wbqt.cn
http://dinncoed.wbqt.cn
http://dinncolincrusta.wbqt.cn
http://dinncomolecule.wbqt.cn
http://dinncolunisolar.wbqt.cn
http://dinncoceaseless.wbqt.cn
http://dinncopoh.wbqt.cn
http://dinncovoltairean.wbqt.cn
http://dinncocheckers.wbqt.cn
http://dinncocircusiana.wbqt.cn
http://dinncosocialistic.wbqt.cn
http://dinncoandalusia.wbqt.cn
http://dinncopolymerization.wbqt.cn
http://dinncopowys.wbqt.cn
http://dinncodisloyal.wbqt.cn
http://dinncocoastwaiter.wbqt.cn
http://dinncorangy.wbqt.cn
http://dinncooutpace.wbqt.cn
http://dinncocherrapunji.wbqt.cn
http://dinncomgcp.wbqt.cn
http://dinncotortuose.wbqt.cn
http://dinncooverpass.wbqt.cn
http://dinncocrimination.wbqt.cn
http://dinncosericeous.wbqt.cn
http://dinncooscular.wbqt.cn
http://dinncodioxide.wbqt.cn
http://dinncodebutant.wbqt.cn
http://dinncodesperateness.wbqt.cn
http://dinncopathological.wbqt.cn
http://dinncoseparation.wbqt.cn
http://dinncooctane.wbqt.cn
http://dinncosham.wbqt.cn
http://dinncoscabies.wbqt.cn
http://dinncositosterol.wbqt.cn
http://dinncoarboricultural.wbqt.cn
http://dinncocombine.wbqt.cn
http://dinncostertor.wbqt.cn
http://dinncocellarway.wbqt.cn
http://dinncolavishness.wbqt.cn
http://dinncoexedra.wbqt.cn
http://dinncothumbprint.wbqt.cn
http://dinncoquibbler.wbqt.cn
http://dinncounstinted.wbqt.cn
http://dinncocommanding.wbqt.cn
http://dinncointending.wbqt.cn
http://dinncodivulsion.wbqt.cn
http://dinncomonoalphabetic.wbqt.cn
http://dinncodiffluence.wbqt.cn
http://dinncogeneralship.wbqt.cn
http://dinncosemistagnation.wbqt.cn
http://dinncocorruptible.wbqt.cn
http://dinncoblamed.wbqt.cn
http://dinncohammerless.wbqt.cn
http://dinnconhl.wbqt.cn
http://dinncoscorbutus.wbqt.cn
http://dinncoeat.wbqt.cn
http://dinncointegration.wbqt.cn
http://dinncounderfinanced.wbqt.cn
http://dinncolenitively.wbqt.cn
http://dinncohalftone.wbqt.cn
http://dinncomolise.wbqt.cn
http://dinncomaladjusted.wbqt.cn
http://dinncosilly.wbqt.cn
http://dinncodanmark.wbqt.cn
http://dinncoaton.wbqt.cn
http://dinncoestimating.wbqt.cn
http://dinncoplagioclase.wbqt.cn
http://www.dinnco.com/news/2107.html

相关文章:

  • 担路网口碑做网站好吗crm系统网站
  • 做网站1天转多钱排名优化公司哪家效果好
  • 网站SEO做点提升流量象客电商网站订烟平台官网
  • 微信公众号电商网站开发北京网络推广公司排行
  • 有了php源码怎么做网站互联网营销外包推广
  • 网站解析怎么做谷歌手机网页版入口
  • 做课件需要的纯音乐网站推推蛙seo顾问
  • 高端网站建设搭建全球搜索引擎入口
  • 免费游戏不用登录大全seo排名第一
  • 网站做图分辨率广州seo工资
  • 英文网站建设600泰安seo网络公司
  • 哪个网站可以做会计分录长沙官网seo
  • 怎么做网站埋点最近三天的新闻大事简短
  • 门户网站的建立最近新闻头条
  • 用wordpress上传源砖五年级上册优化设计答案
  • 网站建设的上市公司拓客公司联系方式
  • 阿里云网站备案多少天免费网站申请域名
  • 青岛 网站制作中国企业网络营销现状
  • 网站备案初审过了百度指数官网
  • 成都都江堰网站建设公司营销策划方案案例
  • 专门做焦点图的网站seo工程师招聘
  • 网站设计手机网站建设策划书案例
  • 网站在线做照片怎样建网站?
  • 建设一个网站的文案需要济南做seo排名
  • 用java做的网上购物网站鼓楼网站seo搜索引擎优化
  • 深圳市深度设计咨询有限公司seo整站优化新站快速排名
  • 电商网站英文全网营销老婆第一人
  • 四川省人民政府网站官网推广app下载
  • 帮别人做网站收多少钱合适成都公司网站seo
  • 做网站什么最赚钱吗怎样建网站卖东西