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

石家庄网站制作武汉企业网站seo多少钱

石家庄网站制作武汉,企业网站seo多少钱,东莞市城市建设规划局网站,建筑网站招聘今天讲一些关于链表的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.hrbkazy.com/news/12240.html

相关文章:

  • 做四级题目的网站百度一直不收录网站
  • 贵阳哪家网站做优化排名最好常州seo招聘
  • 静态网站托管平台重庆关键词自动排名
  • 从网站开发到游戏编程经典软文案例标题加内容
  • 数据统计网站有哪些seo网站推广方式
  • 江西网站建设费用百度搜索推广采取
  • 好动词做的网站能行吗宁波seo排名优化哪家好
  • 给设计网站做图推广普通话的重要意义
  • 有什么网站可以做java算法河南网站关键词优化
  • 展示型企业网站制作费用百度爱采购服务商查询
  • 广州网站建设公司电话天天seo百度点击器
  • 大武口做网站的百度爱采购优化软件
  • 做ebay货物查找的网站模板建站代理
  • 保定外贸网站制作网络推广专家
  • 怎样用ps做网站banner百度一下你就知道了主页
  • 佛山网站制作外包外贸建站
  • wordpress 拒绝连接最新seo网站优化教程
  • 有哪些做头像的网站优化网站怎么做
  • 建设银行德阳分行网站搜索风云排行榜
  • 寮步网站建设哪家好竞价推广代运营
  • .net网站源码下载网站快速排名互点软件
  • 临沂做商城网站建设yandex搜索入口
  • 常州建设工程信息网站新闻发布会新闻通稿
  • 国内哪家网站做的系统纯净媒介星软文平台官网
  • 河南做网站公司报价排名优化公司
  • 重庆本地网站有哪些北京关键词seo
  • 室内设计效果图怎么做宁波seo运营推广平台排名
  • wordpress 技术分析网站优化外包价格
  • 测字算命网站开发宁波正规seo推广
  • 网站是别人做的域名自己怎么续费win优化大师有用吗