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

南宁seo标准南昌seo排名收费

南宁seo标准,南昌seo排名收费,网站推广的方式有,中国室内设计联盟网文章目录 前言一、反转链表二、移除链表元素三、链表中倒数第K个结点四、相交链表五、链表的中间结点 前言 一、反转链表 力扣206:反转链表- - -点击此处传送 思路图: 方法一:改变指向 方法二: 代码: //方法一 /…

文章目录

  • 前言
  • 一、反转链表
  • 二、移除链表元素
  • 三、链表中倒数第K个结点
  • 四、相交链表
  • 五、链表的中间结点


前言

一、反转链表

力扣206:反转链表- - -点击此处传送
在这里插入图片描述
思路图:
方法一:改变指向
在这里插入图片描述
方法二:
在这里插入图片描述
代码:

//方法一
//改变指向
struct ListNode* reverseList(struct ListNode* head) {//判断空if(head==NULL){return NULL;}struct ListNode*n1,*n2,*n3;n1=NULL;n2=head;n3=head->next;while(n2){n2->next=n1;n1=n2;n2=n3;if(n3){n3=n3->next;}}return n1;
}//方法二
//头插
struct ListNode* reverseList(struct ListNode* head) {struct ListNode* cur = head;struct ListNode* newhead = NULL;while(cur){struct ListNode* next=cur->next;cur->next=newhead;newhead=cur;cur=next;}return newhead;
}

二、移除链表元素

力扣203:移除链表元素- - -点击此处传送
在这里插入图片描述
思路图:

在这里插入图片描述
方法2:
当然这题也可以使用带哨兵位的结点
在这里插入图片描述

代码

//方法1:
struct ListNode* removeElements(struct ListNode* head, int val) {struct ListNode*cur=head;struct ListNode*newhead=NULL;struct ListNode*tail=NULL;while(cur){if(cur->val!=val){if(tail==NULL){newhead=tail=cur;}else{tail->next=cur;tail=tail->next;}cur=cur->next;}else{struct ListNode*tmp=cur;cur=cur->next;free(tmp);}}if(tail)tail->next=NULL;return newhead; 
}//方法2:
struct ListNode* removeElements(struct ListNode* head, int val) {struct ListNode* cur=head;struct ListNode* tail=NULL;struct ListNode* newhead=NULL;//哨兵位newhead=tail=(struct ListNode*)malloc(sizeof(struct ListNode));while(cur){if(cur->val!=val){//尾插tail->next=cur;tail=tail->next;cur=cur->next;}else{struct ListNode*tmp=cur;cur=cur->next;free(tmp);}}tail->next=NULL;struct ListNode*tmp=newhead;newhead=newhead->next;free(tmp);return newhead;
}

三、链表中倒数第K个结点

牛客网:链表中倒数第K个结点- - -点击此处传送
在这里插入图片描述
思路图:
在这里插入图片描述
代码:

//牛客网代码模型
struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) {// write code herestruct ListNode* fast=pListHead;struct ListNode* slow=pListHead;while(k--){//空链表if(fast==NULL)return NULL;fast=fast->next;}while(fast){fast=fast->next;slow=slow->next;}return slow;
}

四、相交链表

力扣160:相交链表- - -点击此处传送
在这里插入图片描述
思路图:
在这里插入图片描述
在这里插入图片描述

代码:

//思路2:
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {struct ListNode*curA=headA;struct ListNode*curB=headB;int lenA=0;int lenB=0;//计算链表A的长度while(curA->next){lenA++;curA=curA->next;}//计算链表B的长度while(curB->next){lenB++;curB=curB->next;}//无交点if(curA!=curB){return NULL;}//用绝对值求出差值int n=abs(lenA-lenB);struct ListNode*longList=headA;struct ListNode*shortList=headB;//若B长if(lenB>lenA){//长链表为BlongList=headB;//短链表为AshortList=headA;}//让长链表B先走差值while(n--){longList=longList->next;}//两链表一起走while(longList!=shortList){longList=longList->next;shortList=shortList->next;}return longList;
}

五、链表的中间结点

力扣876:链表的中间结点- - -点击此处传送
在这里插入图片描述
思路图:
在这里插入图片描述
代码:

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;
}
http://www.shuangfujiaoyu.com/news/45246.html

相关文章:

  • 网站建设价钱百度企业官网认证
  • 引擎网站推广法怎么做网站建设推广
  • 南通专业做网站中国新冠一共死去的人数
  • 哪些做网站的公司中国楼市最新消息
  • 温州做网站百度云服务器
  • 做暧昧的小视频网站2企业网站是什么
  • 网站建设好不好模板网站建设
  • 东莞网站设计多少钱seo优化需要做什么
  • 哪些h5网站比较好可以免费做网站推广的平台
  • 西安电商平台网站建设搜索引擎营销总结
  • 广州高端网站制作公司哪家好百度一下你就知道主页
  • 电商网站怎样做seo关键词优化要多少钱
  • 泰安市住房建设局网站水果网络营销推广方案
  • 做游戏视频网站有哪些百度网站收录提交
  • 旅游响应式网站建设百度网盘下载安装
  • 网站同时做竞价和优化可以吗seo优化关键词排名优化
  • 中国建设工程招投标网站营销网站方案设计
  • 中国互联网站建设中心建站公司网站建设价格
  • 做c2c网站的弊端网站快速排名推广软件
  • 关于网站建设领导分工谷歌搜索引擎入口2023
  • 网站如何做反爬天津百度seo推广
  • 企业网站php源码推广策略及推广方式
  • 企业网站建设找智恒网络推广网站都有哪些
  • 上海网站建设中心开网站需要多少钱
  • 中国体育新闻工作者协会广州网站优化公司排名
  • 开发网站网络公司怎么样优化seo
  • 网站小样用什么做ebay欧洲站网址
  • 网站备案信息真实核验单 下载怎么进入百度推广账户
  • 怀化网站建设网站谷歌seo排名
  • 网站建设方案书范文百度推广如何计费