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

交友网站怎样做百度网站搜索排名

交友网站怎样做,百度网站搜索排名,wordpress自定义添加css样式,网络互联网推广今天讲一些关于链表的Oj题,相信你看完对链表又提升一个档次。 题目一 思路一 遍历一遍链表是Val值得时候free这个,然后我们往后走,一直走到末尾空指针得时候,新链表就是我们得答案,那我们用代码来表示一下吧。 struct…

在这里插入图片描述
今天讲一些关于链表的Oj题,相信你看完对链表又提升一个档次。

题目一

在这里插入图片描述
思路一
遍历一遍链表是Val值得时候free这个,然后我们往后走,一直走到末尾空指针得时候,新链表就是我们得答案,那我们用代码来表示一下吧。


struct ListNode* removeElements(struct ListNode* head, int val){struct ListNode*cur=head;struct ListNode*pre=NULL;while(cur){if(cur->val==val){if(pre==NULL){head=cur->next;free(cur);cur=head;}else{pre->next=cur->next;free(cur);cur=pre->next;}}else{pre=cur;cur=cur->next;}}return head;
}

思路二
不是val我们就拿下来,是val就跳过,放到新链表中。

struct ListNode* removeElements(struct ListNode* head, int val){struct ListNode*tail=NULL;struct ListNode*cur=head;head=NULL;while(cur){if(cur->val==val){cur=cur->next;}else{if(tail==NULL){head=tail=cur;}else{tail->next=cur;tail=tail->next;}cur=cur->next;}}if(tail)tail->next=NULL;   return head;
}

思路三
带哨兵位得头节点得方法,是val拿下来,不是跳过。


struct ListNode* removeElements(struct ListNode* head, int val){struct ListNode*cur=head;head=(struct ListNode*)malloc(sizeof(struct ListNode));struct ListNode*tail=head;tail->next=NULL;while(cur){if(cur->val==val){struct ListNode*del=cur;cur=cur->next;free(del);}else{tail->next=cur;cur=cur->next;tail=tail->next;}}tail->next=NULL;struct ListNode*del=head->next;free(head);return del;}

题目二

在这里插入图片描述

这题我们可以改变指向,给三个指针变量,变方向就可以解决。

struct ListNode* reverseList(struct ListNode* head){if(head==NULL)return NULL;struct ListNode*cur=head;struct ListNode*pre=NULL;struct ListNode*next=cur->next;while(cur){cur->next=pre;pre=cur;cur=next;if(next)next=next->next;}return pre;
}

思路二
头插到新链表就可以了。

struct ListNode* reverseList(struct ListNode* head){struct ListNode*cur=head;struct ListNode*phead=NULL;while(cur){struct ListNode*next=cur->next;cur->next=phead;phead=cur;cur=next;}return phead;
}

题目三

在这里插入图片描述

用快慢指针,快走两步,慢走一步,就可以解决。

struct ListNode* middleNode(struct ListNode* head){struct ListNode*slow=head;struct ListNode*fast=head;while(fast && fast->next){slow=slow->next;fast=fast->next;if(fast)fast=fast->next;}return slow;
}

题目四

struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) {struct ListNode*slow=pListHead;struct ListNode*fast=pListHead;while((k--)){if(fast==NULL)return NULL;fast=fast->next;}while(fast){fast=fast->next;slow=slow->next;}return slow;
}

在这里插入图片描述

这题和快慢指针差不多,先让快指针走k步,然后同时走,结束条件就是快指为空的时候。

今天就先分享四道题目,后面再继续分享几道!!!谢谢大家观看

http://www.zhongyajixie.com/news/45973.html

相关文章:

  • 凡科互动游戏修改速度怎么网站排名seo
  • 江苏徐州网站建设百度本地惠生活推广
  • ...无锡网站制作谷歌google搜索引擎入口
  • 品牌官方网站建设需要什么石家庄seo公司
  • 移动网站建设学习泰州seo平台
  • 做网站为什么先交定金广州线下教学
  • wordpress dux5.1冯耀宗seo课程
  • 苏州吴中区做网站网上的推广公司
  • 石家庄网站建设刘华青岛网络工程优化
  • 朝阳网站制作公司搜索排名影响因素
  • 网站的论坛怎么做品牌推广网络公司
  • php网站搭建教程广州最新疫情最新消息
  • 用什么软件做动漫视频网站seo赚钱方式
  • 手机网站的建设培训班报名
  • 做服装必须看的十大网站引擎优化seo是什么
  • 0311网站建设百度首页纯净版
  • 网站 审批号百度seo排名培训优化
  • 建设企业网站的人员组成深圳营销推广引流公司
  • 外贸网站建设收款通道百度一下官网页
  • 公务员写作材料网站烟台seo快速排名
  • 网站统计数据怎么做c成apa格式成都网站seo性价比高
  • 可信网站认证不做百度手机关键词排名工具
  • iapp网站做软件教程新公司如何做推广
  • 六安市建设银行网站58同城推广
  • magento做的网站有哪些外贸公司如何做推广
  • 西安 医疗网站建设十大互联网平台
  • 做住宿的有几个网站购买链接怎么买
  • b2b网站的主要功能吉林刷关键词排名优化软件
  • 智达世通建设集团有限公司网站58网络推广
  • 建立网站备案的法律依据seo中心