leetcode 234 Palindrome Linked List C++
来源:互联网 发布:java注释的作用 编辑:程序博客网 时间:2024/05/17 04:42
得到链表后半段的首地址,然后翻转,然后依次比较即可。
ListNode* reverseList(ListNode* head){ ListNode * pre = NULL; while(head){ ListNode *tmp = head->next; head->next = pre; pre = head; head = tmp; } return pre; } bool isPalindrome(ListNode* head) { if(!head||!head->next) return true; ListNode* fast; ListNode* slow; fast = slow = head; while(fast&&fast->next){ slow = slow->next; fast = fast->next->next; } if(fast){ slow = slow->next; } slow = reverseList(slow); while(slow){ if(head->val != slow->val) return false; head = head->next; slow = slow->next; } return true; }
0 0
- [leetcode-234]Palindrome Linked List (C)
- [leetcode-234]Palindrome Linked List (C)
- [C语言][LeetCode][234]Palindrome Linked List
- Palindrome Linked List leetcode 234
- 【LeetCode】234 Palindrome Linked List
- Palindrome Linked List (leetcode 234)
- leetcode 234: Palindrome Linked List
- leetcode[234]:Palindrome Linked List
- LeetCode 234Palindrome Linked List
- leetcode-234-Palindrome Linked List
- [Leetcode 234] Palindrome Linked List
- Leetcode #234 Palindrome Linked List
- [LeetCode 234] Palindrome Linked List
- Leetcode 234 Palindrome Linked List
- LeetCode(234)Palindrome Linked List
- leetcode 234: Palindrome Linked List
- [Leetcode]#234 Palindrome Linked List
- leetcode 234 Palindrome Linked list
- Java线程池使用说明
- <OJ_Sicily>Greatest Common Divisors
- 网络视频刷单调查:4分钟免费刷2.2万300元能买4000万点击
- Range——克隆内容cloneContents()
- Activity七大生命周期详解
- leetcode 234 Palindrome Linked List C++
- LeetCode:Longest Consecutive Sequence
- 星期几的不同脚本写法(推荐)和JS年月日格式
- G-Dezender批量解密
- 在Windows上编译Wireshark源代码
- Android View工作机制(4)— 我们该什么时候获取View的高宽?
- 模仿微信通讯录侧边栏快速索引
- cocos2d 性能优化1
- C++ 字符串字面值常量的问题