题解 | #链表的回文结构#

链表的回文结构

http://www.nowcoder.com/practice/d281619e4b3e4a60a2cc66ea32855bfa

/* struct ListNode { int val; struct ListNode next; ListNode(int x) : val(x), next(NULL) {} };/ struct ListNode* middleNode(struct ListNode* head) { struct ListNode*slow,*fast; slow=fast=head; while(fast&&fast->next) { slow=slow->next; fast=fast->next->next; } return slow; }

struct ListNode* reverseList(struct ListNode* head) {

struct ListNodecur=head; struct ListNodenewhead=NULL; while(cur) { struct ListNodenext=cur->next; //头插 cur->next=newhead; newhead=cur; //迭代往后走 cur=next; } return newhead; } class PalindromeList { public: bool chkPalindrome(ListNode A) { // write code here struct ListNodemid= middleNode(A); struct ListNoderHead=reverseList(mid); struct ListNodecurA=A; struct ListNodecurR=rHead; while(curA&&curR) { if(curA->val!=curR->val) { return false; } else { curA=curA->next; curR=curR->next; } } return true; } };

全部评论

相关推荐

小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
07-11 13:16
湖南工学院 Java
坚定的芭乐反对画饼_...:谁也不知道,毕竟现在的互联网和十年前已经完全不同了,谁都无法预测未来
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务