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

免费做网站平台广东省建设网站

免费做网站平台,广东省建设网站,保定关键词优化排名,临沂市建设局网站公示hi#xff0c;bro—— 目录 5、 链表分割 6、 链表的回文结构 7、 相交链表 8、 环形链表 【思考】 —————————————— DEAD POOL —————————————— 5、 链表分割 /* struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), …hibro—— 目录 5、 链表分割 6、 链表的回文结构 7、 相交链表 8、 环形链表 【思考】 —————————————— DEAD POOL —————————————— 5、 链表分割 /* struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {} };*/ #include functional class Partition { public:ListNode* partition(ListNode* pHead, int x){//创建新的大小链表ListNode* lessHead,*lessTail;lessHeadlessTail(ListNode*)malloc(sizeof(ListNode));ListNode* greaterHead,*greaterTail;greaterHeadgreaterTail(ListNode*)malloc(sizeof(ListNode));//创建新的头结点遍历数组ListNode* pcurpHead;while(pcur){if(pcur-valx){//尾插到小链表lessTail-nextpcur;lessTaillessTail-next;}else{//尾插到大链表greaterTail-nextpcur;greaterTailgreaterTail-next;}pcurpcur-next;}//大小链表首尾相连lessTail-nextgreaterHead-next;greaterTail-nextNULL;ListNode* retlessHead-next;free(lessHead);free(greaterHead);lessHeadNULL;greaterHeadNULL;return ret;} }; 6、 链表的回文结构 在链表中不可回找但是数组可以回找所以我们可以把链表中的数据放到数组中。 思路1创建新数组遍历原链表将链表中的值放到数组中然后在数组中判断是否为回文结构。 因为题目中提前对链表的长度进行了限制若不限制空间复杂度为ON就不符合题目的条件了 /* struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {} };*/ class PalindromeList { public:bool chkPalindrome(ListNode* A) {int arr[900]{0};ListNode* pcurA;int i0;//将链表中的数据赋给数组while(pcur){arr[i]pcur-val;pcurpcur-next;}//i为链表中结点的个数//判断数组中的值是否为回文结构int left0;int righti-1;while(leftright){if(arr[left]!arr[right]){return false;}left;right--;}return true;} }; 思路2反转链表这种方法的时间复杂度为ON空间复杂度为O1 1找原链表的中间结点“快慢指针” 2将中间结点及之后的结点进行反转 3从原链表的头结点和新链表的头结点开始遍历比较。 /* struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {} };*/ class PalindromeList { public://找中间结点ListNode* findMidNode(ListNode* phead){ListNode* slow,*fast;slowfastphead;while(fastfast-next){slowslow-next;fastfast-next-next;}return slow;}//反转链表ListNode* reverseList(ListNode* phead){ListNode* n1,*n2,*n3;n1NULL;n2phead;n3n2-next;while(n2){n2-nextn1;n1n2;n2n3;if(n3)n3n3-next;}return n1;}bool chkPalindrome(ListNode* A) {//1.找中间结点ListNode* midfindMidNode(A);//2.反转链表ListNode* rightreverseList(mid);//3.遍历比较ListNode* leftA;while(right){if(left-val!right-val)return false;leftleft-next;rightright-next;}return true;} }; 7、 相交链表 思路1判断两个链表是否相等 2返回两个单链表相交的起始结点 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/typedef struct ListNode ListNode; struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {ListNode* l1headA;ListNode* l2headB;int countA0;int countB0;//求两个链表的长度while(l1){countA;l1l1-next;}while(l2){l2l2-next;countB;}//求链表长度差值的绝对值int gapabs(countA-countB);//判断哪个是长短链表ListNode* longListheadA;ListNode* shortListheadB;if(countAcountB){longListheadB;shortListheadA; }//让两个链表在同一起跑线while(gap--){longListlongList-next;}//判断两个链表是否相交while(longListshortList){//相交if(longListshortList){return longList;}longListlongList-next;shortListshortList-next;}//不相交return NULL; } 8、 环形链表 思路  /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/typedef struct ListNode ListNode; bool hasCycle(struct ListNode *head) {ListNode* slowhead;ListNode* fasthead;while(fastfast-next){slowslow-next;fastfast-next-next;if(slowfast){return true;}}return false; } 【思考】 头好痒感觉要长脑子了 完——  Relaxing Time ! —————————————— DEAD POOL —————————————— https://t3.kugou.com/song.html?idc35Fp66CPV2https://t3.kugou.com/song.html?idc35Fp66CPV2 能力越大越没责任  Bye ~~~
http://www.hkea.cn/news/14544687/

相关文章:

  • 英文网站排版设计广告公司网站建设
  • 宝塔面板wordpress多站点挂机宝 可以做网站
  • 网站域名的作用免费推广店铺的网站
  • 网站模板组件电子商务网站建设含义
  • 杭州做网站需要多少钱nginx和wordpress
  • 企业如何注册网站wordpress段子模板
  • 有的域名怎样做网站期末网站设计做什么网站比较好
  • 太原百度推广制作个性商城网站网站左侧导航代码
  • 重庆建站服务商wordpress全站注明
  • 爱站网ip反域名查询宝安区做网站
  • 徐州做网站的公司企业网站系统设计与实现
  • 网站推广都有哪些微商网站
  • 电商平台网站建设网站跳转站代码
  • 移动网站 制作建设企业网站的
  • 网站改版 数据迁移wordpress付费汉化主题
  • 温州做外贸网站湖南建设局网站
  • seo竞争对手网站分析沈阳网势科技有限公司怎么样
  • wordpress图片整站如何用手机做网站
  • 郑州网站建设求职简历做网站怎么云存储
  • 网站备案号密码网站建设网站徒手整形
  • 建设邮费自己的网站 要不要购买服务器的wordpress 置顶
  • 基于asp网站开发 论文有人知道网站怎么做吗
  • dedecms三合一网站源码笑话网站源码下载
  • 网站程上传php网站开发小程序
  • 网站建设 实施计划网站建设沟通
  • 网站建设的合理建议南通网站制作公司
  • 知名网站建设制作阳江招聘网最新招聘2023
  • 网站一元空间有哪些呀帮忙建网站的人
  • 电子商务网站建设功能wordpress 变更域名
  • 修机械师怎么做我小样网站角仰望阿里云 企业 网站