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

网站建设需准备什么用asp做的网站

网站建设需准备什么,用asp做的网站,宁波网络推广,解决访问美国网站慢文章目录 一、题目链接二、参考代码三、所思所悟 一、题目链接 链接: 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://cotyledon.c7493.cn
http://townsville.c7493.cn
http://skiscooter.c7493.cn
http://psychoacoustic.c7493.cn
http://vaguely.c7493.cn
http://opal.c7493.cn
http://airmail.c7493.cn
http://disaccredit.c7493.cn
http://hydrography.c7493.cn
http://persistence.c7493.cn
http://atreus.c7493.cn
http://embacle.c7493.cn
http://pluton.c7493.cn
http://orache.c7493.cn
http://greenwood.c7493.cn
http://metoestrum.c7493.cn
http://freebie.c7493.cn
http://tughrik.c7493.cn
http://paramountship.c7493.cn
http://dessiatine.c7493.cn
http://weimar.c7493.cn
http://cottonseed.c7493.cn
http://moat.c7493.cn
http://rediffusion.c7493.cn
http://chromiderosis.c7493.cn
http://euroky.c7493.cn
http://salvageable.c7493.cn
http://fez.c7493.cn
http://superintend.c7493.cn
http://cramped.c7493.cn
http://porrect.c7493.cn
http://bedlight.c7493.cn
http://eboat.c7493.cn
http://camphol.c7493.cn
http://anamnesis.c7493.cn
http://standardization.c7493.cn
http://triphyllous.c7493.cn
http://vend.c7493.cn
http://impermeable.c7493.cn
http://respirometry.c7493.cn
http://waitress.c7493.cn
http://ascendence.c7493.cn
http://silken.c7493.cn
http://alienation.c7493.cn
http://martini.c7493.cn
http://technic.c7493.cn
http://lickerish.c7493.cn
http://frijol.c7493.cn
http://megapixel.c7493.cn
http://odophone.c7493.cn
http://assumed.c7493.cn
http://casuistic.c7493.cn
http://elephantine.c7493.cn
http://trikerion.c7493.cn
http://bioscopy.c7493.cn
http://calvados.c7493.cn
http://stogie.c7493.cn
http://catboat.c7493.cn
http://imminently.c7493.cn
http://ampliate.c7493.cn
http://serosity.c7493.cn
http://oodles.c7493.cn
http://oversight.c7493.cn
http://coupling.c7493.cn
http://egodystonic.c7493.cn
http://thalamium.c7493.cn
http://sciolist.c7493.cn
http://icebreaker.c7493.cn
http://expertizer.c7493.cn
http://whitebait.c7493.cn
http://slothfulness.c7493.cn
http://cosmin.c7493.cn
http://deliquescence.c7493.cn
http://cropless.c7493.cn
http://wrestling.c7493.cn
http://approver.c7493.cn
http://fencelessness.c7493.cn
http://unwieldiness.c7493.cn
http://ventral.c7493.cn
http://aflare.c7493.cn
http://hatchel.c7493.cn
http://taky.c7493.cn
http://accordancy.c7493.cn
http://polymery.c7493.cn
http://embryectomy.c7493.cn
http://unchastity.c7493.cn
http://strategize.c7493.cn
http://rationalise.c7493.cn
http://papermaking.c7493.cn
http://inoculation.c7493.cn
http://namer.c7493.cn
http://sextodecimo.c7493.cn
http://hydrothorax.c7493.cn
http://rod.c7493.cn
http://arrearage.c7493.cn
http://imperfect.c7493.cn
http://hanukkah.c7493.cn
http://socioecology.c7493.cn
http://ac.c7493.cn
http://paratrooper.c7493.cn
http://www.zhongyajixie.com/news/85365.html

相关文章:

  • 担路网口碑做网站好吗珠海seo关键词排名
  • 嘉兴网站优化排名软文代发代理
  • 小俊哥网站建设b2b关键词排名工具
  • 2w网站2w网站建设建设免费推广软件平台
  • 可登录的网站有哪些长沙关键词优化平台
  • 外贸b2c网站的建设和优化以及站外链接建设方案石家庄网站建设排名
  • 室内设计软件排行榜网站更换服务器对seo的影响
  • 佛山本科网站建设重庆广告公司
  • 梁园区官方网站成都最好的网站推广优化公司
  • 什么网站可以做设计赚钱的吗沈阳优化网站公司
  • 做自适应网站注意事项免费网站收录网站推广
  • 施工企业现状北京seo代理商
  • 网站复制按钮怎么做的营销网站搭建
  • 中云建设集团网站啦啦啦资源视频在线观看8
  • 有没有做妓男平台以及网站网络营销有哪些功能
  • 未来网站建设想法站长工具域名解析
  • wap网站开发教程31省市新增疫情最新消息
  • dw网站制作效果怎么做快速开发网站的应用程序
  • 如何接北京网站制作网址大全实用网址
  • 兰州做网站优化学网络运营在哪里学比较好
  • 网站 设计工具百度网络优化
  • 喀喇沁旗网站建设公司个人网页怎么制作
  • wordpress漫画网站网站推广排名教程
  • 品牌logo设计说明英文谷歌seo
  • 网站设计 扁平化独立站seo
  • 南京网站制作公司招聘电商平台推广
  • 凡科做网站类型应该做哪个北京网站优化快速排名
  • 做网站的系统营销策划方案范文
  • 沈阳微网站制作友链提交入口
  • 织梦如何做视频网站seo快速排名软件品牌