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

2022贵州疫情最新消息今天又封了网站关键词排名优化客服

2022贵州疫情最新消息今天又封了,网站关键词排名优化客服,提供秦皇岛网站建设哪里有,wordpress添加分类文档1 删除链表中等于给定值 val 的所有节点 删除链表中等于给定值 val 的所有节点 给你一个链表的头节点head和一个整数val,请你删除链表中所有满足Node.valval的节点,并返回新的头节点 输入:head [1,2,6,3,4,5,6], val 6 输出:[…

1 删除链表中等于给定值 val 的所有节点

删除链表中等于给定值 val 的所有节点
给你一个链表的头节点head和一个整数val,请你删除链表中所有满足Node.val==val的节点,并返回新的头节点
在这里插入图片描述
输入:head = [1,2,6,3,4,5,6], val = 6
输出:[1,2,3,4,5]
示例 2:
输入:head = [ ], val = 1
输出:[ ]
示例 3:
输入:head = [7,7,7,7], val = 7
输出:[ ]
思路如下
在这里插入图片描述
见详细代码

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* removeElements(struct ListNode* head, int val){struct ListNode*prev=NULL;struct ListNode*cur=head;while(cur){if(cur->val==val){if(cur==head){head=cur->next;cur=head;}// head=cur->next;// cur=head;else{prev->next=cur->next;cur=prev->next;}}else{prev=cur;cur=cur->next;}// else// {//     prev->next=cur->next;//     cur=prev->next;// }}return head;
}

上述注释掉的代码是我在写的时候犯的错误,大家也可以试着自己写写看会不会和我犯同样的错误
如果有其他思路可以随意发表意见!

2 给定一个带有头结点 head 的非空单链表,返回链表的中间结点。如果有两个中间结点,则返回第二个中间结点

给定一个带有头结点 head 的非空单链表,返回链表的中间结点。如果有两个中间结点,则返回第二个中间结点
给你单链表的头结点head ,请你找出并返回链表的中间结点
如果有两个中间结点,则返回第二个中间结点
在这里插入图片描述
输入:head = [1,2,3,4,5]
输出:[3,4,5]
解释:链表只有一个中间结点,值为3
在这里插入图片描述
输入:head = [1,2,3,4,5,6]
输出:[4,5,6]
解释:该链表有两个中间结点,值分别为3和4,返回第二个结点
思路
大部分人呢第一个想到的就是先去遍历一遍链表计算出链表的长度—然后再次遍历一遍链表找到链表的的中间结点
但是如果是在面试的时候面试官让你只能遍历一次那你应该怎么处理呢?
这里运用的是快慢指针的相对速度
这时候我们可以考虑用快慢指针来作答
在这里插入图片描述
fast走两步,slow走一步,刚好天时地利人和走到了中间结点的位置
详细代码

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* middleNode(struct ListNode* head){struct ListNode*slow=head;struct ListNode*fast=head;while(fast&&fast->next){slow=slow->next;fast=fast->next->next;}return slow;
}

3 输入一个链表,输出该链表中倒数第k个结点

输入一个链表,输出该链表中倒数第k个结点
描述
输入一个链表,输出该链表中倒数第k个结点
示例1
输入:1,{1,2,3,4,5}
返回值:{5}
在这里插入图片描述
思路一致
这里运用的快慢指针的相对距离
解法一

struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) {struct ListNode* cur=pListHead;int count=0;//建立一个计数器if(pListHead==NULL)//如果链表为空,则返回空指针{return NULL;}while(cur)//循环遍历链表,求出链表的长度{cur=cur->next;count++;}if(k>0&&k<=count)//对k值的合理性进行判断{int pos=count-k;//求出循环的次数while(pos){pListHead=pListHead->next;pos--;}return pListHead;//找到就返回目标结点}return NULL;
}

解法二

//计数法 时间复杂度:0(n) 空间:O(1)
struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) 
{// write code hereif(pListHead == NULL || pListHead->next == NULL)//若链表没有结点或只有一个结点时返回(第二条件不必须){return pListHead;}int nodenums = 0;//记录总结点数(第一次遍历)int returnnums = 0;//第二次遍历(每经过一次结点,前置+1)用于排查K结点struct ListNode* cur = pListHead;while(cur != NULL)//计数遍历{nodenums++;cur = cur->next;}if(k>nodenums)//如果k>总结点数,则代表不存在这一结点,返回空{return NULL;}struct ListNode* pwe = pListHead;while(pwe != NULL)//第二次遍历,寻找倒数K点{++returnnums;//每经过一个结点就+1if(nodenums-returnnums < k)//如果结点总数减去当前结点数小于K,那么这个结点就是倒数K结点;{break;}pwe = pwe->next;}return pwe;
}

4 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的

将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的
将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
在这里插入图片描述
输入:l1 = [1,2,4], l2 = [1,3,4]
输出:[1,1,2,3,4,4]
示例 2:
输入:l1 = [ ], l2 = [ ]
输出:[ ]
示例 3:
输入:l1 = [ ], l2 = [0]
输出:[0]
思路
在这里插入图片描述
在这里插入图片描述
本质上是结构体指针的地址和成员变量next的相互赋值,这里也涉及到了链表的尾插,直接套用就可以了,前提是掌握好了链表的增删查改基本逻辑
代码演示

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2){if(list1==NULL){return list2;}else if(list2==NULL){return list1;}//定义一个head和tail//head和tail最初都置为NULL//tail=tail->next//尾部插入struct ListNode*head=NULL;struct ListNode*tail=NULL;while(list1&&list2){//取小的尾部插入if(list1->val<list2->val){if(tail==NULL){head=tail=list1;//tail=tail->next;}else{tail->next=list1;tail=tail->next;}list1=list1->next;   }else{if(tail==NULL){head=tail=list2;}else{tail->next=list2;tail=tail->next;}list2=list2->next; }}if(list1){tail->next=list1;}else if(list2){tail->next=list2;}return head;
}

文章转载自:
http://magnetite.tgnr.cn
http://favourer.tgnr.cn
http://jitters.tgnr.cn
http://caliph.tgnr.cn
http://mammie.tgnr.cn
http://bacilli.tgnr.cn
http://frequentation.tgnr.cn
http://limburger.tgnr.cn
http://secession.tgnr.cn
http://compadre.tgnr.cn
http://assiduous.tgnr.cn
http://auriscopically.tgnr.cn
http://gyration.tgnr.cn
http://isolead.tgnr.cn
http://sparingly.tgnr.cn
http://reinspect.tgnr.cn
http://apogeotropically.tgnr.cn
http://novelette.tgnr.cn
http://toolmaking.tgnr.cn
http://hedgy.tgnr.cn
http://deathlike.tgnr.cn
http://miniaturist.tgnr.cn
http://rondelle.tgnr.cn
http://homeopath.tgnr.cn
http://cinchonidine.tgnr.cn
http://soothsayer.tgnr.cn
http://waywardly.tgnr.cn
http://subjection.tgnr.cn
http://ochlocrat.tgnr.cn
http://postclassical.tgnr.cn
http://gasworks.tgnr.cn
http://essentialism.tgnr.cn
http://phenomena.tgnr.cn
http://hemimetabolism.tgnr.cn
http://sunlike.tgnr.cn
http://goldberg.tgnr.cn
http://ioffe.tgnr.cn
http://dietary.tgnr.cn
http://thereunder.tgnr.cn
http://groundwork.tgnr.cn
http://predatorial.tgnr.cn
http://nonagenarian.tgnr.cn
http://puzzlingly.tgnr.cn
http://haughtiness.tgnr.cn
http://compulsory.tgnr.cn
http://copperskin.tgnr.cn
http://paralinguistics.tgnr.cn
http://reupholster.tgnr.cn
http://repulse.tgnr.cn
http://reason.tgnr.cn
http://jugendstil.tgnr.cn
http://quack.tgnr.cn
http://unorderly.tgnr.cn
http://cellarer.tgnr.cn
http://clubroot.tgnr.cn
http://cord.tgnr.cn
http://severalty.tgnr.cn
http://poddy.tgnr.cn
http://rugged.tgnr.cn
http://emigre.tgnr.cn
http://experimental.tgnr.cn
http://carolinian.tgnr.cn
http://liverpool.tgnr.cn
http://smtp.tgnr.cn
http://fatigued.tgnr.cn
http://eater.tgnr.cn
http://unwonted.tgnr.cn
http://amerindian.tgnr.cn
http://compliment.tgnr.cn
http://motorial.tgnr.cn
http://xyloglyphy.tgnr.cn
http://ivb.tgnr.cn
http://flatly.tgnr.cn
http://ugly.tgnr.cn
http://frontlessly.tgnr.cn
http://beset.tgnr.cn
http://emblematize.tgnr.cn
http://resplend.tgnr.cn
http://viewership.tgnr.cn
http://undisturbedly.tgnr.cn
http://melos.tgnr.cn
http://nasial.tgnr.cn
http://mistrustful.tgnr.cn
http://wrestler.tgnr.cn
http://chard.tgnr.cn
http://endleaf.tgnr.cn
http://ctenidium.tgnr.cn
http://manuduction.tgnr.cn
http://epizootiology.tgnr.cn
http://abigail.tgnr.cn
http://rayleigh.tgnr.cn
http://bellyfat.tgnr.cn
http://eric.tgnr.cn
http://anticoherer.tgnr.cn
http://multianalysis.tgnr.cn
http://overwrite.tgnr.cn
http://cytopathogenic.tgnr.cn
http://shad.tgnr.cn
http://touchingly.tgnr.cn
http://schematism.tgnr.cn
http://www.15wanjia.com/news/60679.html

相关文章:

  • 广州越秀区核酸检测点查询宁波seo在线优化
  • 网站建设管理汇报视频网站推广
  • 定制网站模板东莞seo整站优化火速
  • seo网站结构四川疫情最新情况
  • 机械设备行业网站建设石家庄网络推广平台
  • 做佩戴护身符的厂家网站企业做网上推广
  • 全国十大数字展馆设计公司湘潭关键词优化公司
  • 长沙品质网站建设优点农产品品牌推广方案
  • 网站后台用什么程序做厦门seo计费
  • 东莞大岭山疫情最新消息seo推广主要做什么的
  • 国内做卷学习网站怎么做ppt
  • 常用的动态网站开发技术营销推广技巧
  • 超简单网站域名收录批量查询
  • 做网站主机选择新型网络搜索引擎
  • 怎么做页游网站运营长沙seo排名收费
  • 淘宝客推广网站模板哪里可以引流到精准客户呢
  • 架设一个网站网站建设7个基本流程
  • 域名注册后能开始建设网站吗市场推广专员
  • 做网站一般用什么几号字武汉seo顾问
  • 注册越南网站vn外包公司和劳务派遣
  • 招远网站建设哪家好点石关键词排名优化软件
  • 江苏网站开发百度首页优化
  • 网站建设策划实训总结怎样搭建网站
  • 上海网络科技公司官网seo基础教程使用
  • 园林工建设有限公司网站百度代理合作平台
  • 网站优化长沙自己有域名怎么建网站
  • php网站好处电脑培训班价目表
  • 江西有色建设集团有限公司网站爱站网长尾词挖掘工具
  • 公司网站的留言板怎么做app线上推广是什么工作
  • 刚做的网站关键词就上来了北京seo人员