leetcode 日经贴,Cpp code -Palindrome Linked List
来源:互联网 发布:淘宝查号 编辑:程序博客网 时间:2024/06/08 07:28
Palindrome Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool isPalindrome(ListNode* head) { if (!head || !head->next) { return true; } //find the mid node ListNode *h1 = head, *h2 = head; while (h2 && h2->next) { h1 = h1->next; h2 = h2->next->next; } //reverse the second part ListNode *h3 = h2? h1->next: h1; h2 = h3->next; h3->next = NULL; while (h2) { h1 = h2->next; h2->next = h3; h3 = h2; h2 = h1; } h1 = head; while (h3) { if (h3->val != h1->val) { return false; } h3 = h3->next; h1 = h1->next; } return true; }};
0 0
- leetcode 日经贴,Cpp code -Palindrome Linked List
- leetcode 日经贴,Cpp code -Linked List Cycle
- leetcode 日经贴,Cpp code -Reverse Linked List
- Leetcode 234. Palindrome Linked List (Easy) (cpp)
- leetcode 日经贴,Cpp code -Flatten Binary Tree to Linked List
- leetcode 日经贴,Cpp code -Linked List Cycle II
- leetcode 日经贴,Cpp code -Remove Linked List Elements
- leetcode 日经贴,Cpp code -Reverse Linked List II
- leetcode 日经贴,Cpp code -Delete Node in a Linked List
- LeetCode Palindrome Linked List
- LeetCode - Palindrome Linked List
- leetcode: Palindrome Linked List
- Leetcode: Palindrome Linked List
- leetcode:Palindrome Linked List
- [LeetCode] Palindrome Linked List
- LeetCode || Palindrome Linked List
- 【leetcode】Palindrome Linked List
- LeetCode-Palindrome Linked List
- 使用ViewPager实现左右循环滑动
- OpenStack 2015.1.0 (Kilo)更新日志
- hiho一下 第五十二周(割边 割点)
- Calendar 中getActualMaximumd 功能
- 设计模式读书笔记:Decorator(装饰)
- leetcode 日经贴,Cpp code -Palindrome Linked List
- json格式封装,以及格式转换
- UVa 11137 Ingenuous Cubrency
- 黑马程序员——Java基础---集合
- 新建和配置Phalcon工程
- No unique bean of type is defined: expected single bean but found 0
- 文章标题
- opencv源码之一:cvboost.cpp
- IE 等兼容下的video radio