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

网站发多少篇文章开始做外链工程建设采购有哪些网站

网站发多少篇文章开始做外链,工程建设采购有哪些网站,开发板是什么,山西省建筑工程网文章目录 前言一、反转链表二、移除链表元素三、链表中倒数第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.yayakq.cn/news/345726/

相关文章:

  • 下载网站后怎么做的短网址生成源码下载
  • 网站管理功能图高端品牌包包排行榜前十名
  • 什么叫做营销型网站怎样进网站空间服务器
  • 蕲春住房和城乡建设局网站一步一步教你做网站
  • 门户网站简介便宜建站空间
  • 网站做推广的企业百度seo关键词优化si
  • 旅游网站建设技术有哪些方面wordpress 中文名
  • 微信官方网站是什么做网站要会哪些软件
  • 建设网站需要多少钱济南兴田德润厉害吗抖音短视频制作教程
  • 网站策划界面效果感受心得做品牌文化的网站
  • 哪里免费做网站怎么制作网站表白
  • 网站建设带主机网站群建设原则
  • wordpress更换网站域名上海seo优化
  • 查询关键词密度网站的网址有哪些深圳网站和app建设方案
  • 网站广告联盟怎么做的静安正规的设计公司网站
  • 网站建设平台流程提升学历被骗怎么投诉
  • jsp淘宝客网站wordpress h1 h2
  • 建材网站免费模板吉林省建设信息网站
  • 网站建设必须要具备哪些知识北京网站制作设计推广公司
  • 土巴兔这种网站怎么做邹城网站建设zczwxx
  • 自助网站建设公司电话设计图纸网站
  • 哪些网站用python做的浙江网架公司
  • 网站开发的前景网络建设与运维
  • 网站建设实习周记网站平台建设的流程
  • 专业定制网站制作公司ss免费服务器
  • 复旦学霸张立勇做的有关寺庙网站顺德企业门户网站建设
  • php网站建设含义中国建设局网站招聘
  • 白云区网站开发公司内蒙古城乡建设厅网站资质公告
  • 柳州网站建设公司哪家好网站开发技术孵化
  • 赤峰建设业协会的官方网站人才招聘网站大全