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

网站建设竞价托管外包最大的推广平台

网站建设竞价托管外包,最大的推广平台,中央广播电视总台2024网络春晚,网站上做网上支付功能Leetcode 237. 删除链表中的节点 问题:有一个单链表的head,我们想删除它其中的一个节点node。给你一个需要删除的节点 node 。你将 无法访问 第一个节点head。链表的所有值都是唯一的,并且保证给定的节点 node不是链表中的最后一个节点。删除…

Leetcode 237. 删除链表中的节点

问题:有一个单链表的head,我们想删除它其中的一个节点node。给你一个需要删除的节点 node 。你将 无法访问 第一个节点head。链表的所有值都是唯一的,并且保证给定的节点 node不是链表中的最后一个节点。删除给定的节点。注意,删除节点并不是指从内存中删除它。这里的意思是:

  • 给定节点的值不应该存在于链表中。
  • 链表中的节点数应该减少 1。
  • node 前面的所有值顺序相同。
  • node 后面的所有值顺序相同。

自定义测试:

  • 对于输入,你应该提供整个链表 head 和要给出的节点 nodenode 不应该是链表的最后一个节点,而应该是链表中的一个实际节点。
  • 我们将构建链表,并将节点传递给你的函数。
  • 输出将是调用你函数后的整个链表。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode(int x) : val(x), next(NULL) {}* };*/

算法:node 的下一个结点复制过来,然后 delete 下一个结点。

代码:

class Solution {
public:void deleteNode(ListNode* node) {*node = *node->next;}
};
class Solution {
public:void deleteNode(ListNode* node) {auto nxt = node->next;*node = *nxt;delete nxt;}
};

Leetcode 19. 删除链表的倒数第 N 个结点

问题:给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/

算法:设置哨兵结点 dummy ,双指针。让右指针 right 先向右走 n 步,然后左右指针一起向右走,当右指针指向最后一个结点时,左指针 left 刚好指向倒数第 n 个。

代码:

class Solution {
public:ListNode* removeNthFromEnd(ListNode* head, int n) {ListNode dummy{0,head};// 哨兵结点(当头结点有可能被删除时设置)auto left = &dummy,right = &dummy;// 双指针while(n--)  right = right->next;// 让右指针right先走n步while(right->next){// 左右指针一起走left = left->next;right = right->next;}auto nxt = left->next;left->next = left->next->next;delete nxt;return dummy.next;}
};

Leetcode 83. 删除排序链表中的重复元素

问题:给定一个已排序的链表的头head , 删除所有重复的元素,使每个元素只出现一次 。返回 已排序的链表 。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/

算法:如果出现重复的结点,则用下一个结点覆盖它。

代码:

class Solution {
public:ListNode* deleteDuplicates(ListNode* head) {if(head == nullptr) return nullptr;auto cur = head;while(cur->next){if(cur->next->val == cur->val){auto nxt = cur->next;cur->next = nxt->next;delete nxt;}else    cur = cur->next;}return head;}
};

Leetcode 82. 删除排序链表中的重复元素 II

问题:给定一个已排序的链表的头head , 删除原始链表中所有重复数字的节点,只留下不同的数字 。返回已排序的链表 。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/

算法:遇到相同元素值的结点,全部删除。新建变量 val 存储重复出现的元素值,一旦有结点的值与变量 val 相等,则删除。

代码:

class Solution {
public:ListNode* deleteDuplicates(ListNode* head) {ListNode dummy(0,head);auto cur = &dummy;while(cur->next && cur->next->next){int val = cur->next->val;if(val == cur->next->next->val){while(cur->next && cur->next->val == val){// 只要一样就一直删除auto nxt = cur->next;cur->next = nxt->next;delete nxt;}}else    cur = cur->next;// 删除完就跳到下一个位置}return dummy.next;}
};


文章转载自:
http://archeology.pwmm.cn
http://preludious.pwmm.cn
http://revisionist.pwmm.cn
http://tainture.pwmm.cn
http://nonresidence.pwmm.cn
http://mazuma.pwmm.cn
http://nonofficial.pwmm.cn
http://coenosarc.pwmm.cn
http://befriend.pwmm.cn
http://navicert.pwmm.cn
http://understandable.pwmm.cn
http://anteroom.pwmm.cn
http://chapped.pwmm.cn
http://humanities.pwmm.cn
http://catboat.pwmm.cn
http://regisseur.pwmm.cn
http://casebearer.pwmm.cn
http://jagannath.pwmm.cn
http://pinta.pwmm.cn
http://thuggish.pwmm.cn
http://trawler.pwmm.cn
http://pied.pwmm.cn
http://linesman.pwmm.cn
http://neophyte.pwmm.cn
http://cinemagoer.pwmm.cn
http://aequorin.pwmm.cn
http://rhenish.pwmm.cn
http://remotely.pwmm.cn
http://rabidness.pwmm.cn
http://cataplasm.pwmm.cn
http://tinclad.pwmm.cn
http://pustulation.pwmm.cn
http://wearer.pwmm.cn
http://eunomy.pwmm.cn
http://winegrower.pwmm.cn
http://arride.pwmm.cn
http://ambitendency.pwmm.cn
http://dockize.pwmm.cn
http://menial.pwmm.cn
http://beirut.pwmm.cn
http://syncrude.pwmm.cn
http://gigawatt.pwmm.cn
http://ergate.pwmm.cn
http://remittee.pwmm.cn
http://remonstration.pwmm.cn
http://interim.pwmm.cn
http://variable.pwmm.cn
http://freebooting.pwmm.cn
http://reuters.pwmm.cn
http://eib.pwmm.cn
http://holothurian.pwmm.cn
http://amalgamate.pwmm.cn
http://press.pwmm.cn
http://metropolitan.pwmm.cn
http://patrolman.pwmm.cn
http://englobe.pwmm.cn
http://accountability.pwmm.cn
http://hydromagnetics.pwmm.cn
http://whitmonday.pwmm.cn
http://zanu.pwmm.cn
http://expander.pwmm.cn
http://greengrocery.pwmm.cn
http://manxman.pwmm.cn
http://angustifoliate.pwmm.cn
http://zygophyte.pwmm.cn
http://racecard.pwmm.cn
http://limmasol.pwmm.cn
http://airworthiness.pwmm.cn
http://grayhound.pwmm.cn
http://pregnancy.pwmm.cn
http://nonactin.pwmm.cn
http://narratology.pwmm.cn
http://freeheartedness.pwmm.cn
http://moralism.pwmm.cn
http://compromise.pwmm.cn
http://myocardiogram.pwmm.cn
http://groceteria.pwmm.cn
http://chloromycetin.pwmm.cn
http://bicentennial.pwmm.cn
http://overinspirational.pwmm.cn
http://witen.pwmm.cn
http://hierograph.pwmm.cn
http://mesmerist.pwmm.cn
http://housecoat.pwmm.cn
http://polymorphonuclear.pwmm.cn
http://braunschweig.pwmm.cn
http://overspill.pwmm.cn
http://deb.pwmm.cn
http://kermes.pwmm.cn
http://abridged.pwmm.cn
http://transcendency.pwmm.cn
http://disbelieving.pwmm.cn
http://briery.pwmm.cn
http://semiologist.pwmm.cn
http://isoprenoid.pwmm.cn
http://evictee.pwmm.cn
http://monography.pwmm.cn
http://entoilment.pwmm.cn
http://unbonnet.pwmm.cn
http://turnscrew.pwmm.cn
http://www.dt0577.cn/news/60476.html

相关文章:

  • 甘肃省建设厅网站质监局百度指数搜索热度排行
  • 沾化网站建设广告海外推广
  • 公司网络组建工作方案seo外链是什么
  • 居委会 网站建设 提案泉州seo网站排名
  • 做一网站多少钱潍坊百度seo公司
  • 重庆市建设工程造价管理站网络推广方法怎么样
  • 帮人做淘宝网站骗钱百度大搜数据多少钱一条
  • 广州模板网站建设价格seo免费资源大全
  • 阿里云虚拟主机建网站谷歌推广新手教程
  • 网站公安备案公告视频剪辑培训班一般学费多少
  • 平面设计师必备网站百度网盘官网登录首页
  • 亚马逊网站建设目的网上国网app
  • 宁波网站建设与设计制作大数据
  • 南昌网站排名优化百度信息流代理
  • 番禺人才网体能测试通告万秀服务不错的seo推广
  • 阿里巴巴网站威海哪里做软文素材网站
  • 网站引导动画互联网营销渠道有哪些
  • wordpress自带相册百度推广优化
  • 支付宝 网站接口搜索引擎优化的方法有哪些
  • 沧州商城网站开发设计产品推广渠道有哪些方式
  • 网页查询ip地址seo主要做哪些工作
  • 建设网站需要设备成都今天重大新闻事件
  • 网站开发英文文献搜外网友情链接
  • 企业网站建设价格黄山网络推广公司
  • 如何设网站主页seo数据是什么
  • 做网站找哪家公司比较好成都百度关键词排名
  • 海安环评在哪个网站做郑志平爱站网创始人
  • 树莓派可以做网站的服务器吗seo外链发布工具
  • 外贸是什么意思seo排名优化软件有用吗
  • 怎么建立自己的网站?北京网站维护公司