## 王一兵

Given a singly linked list, determine if it is a palindrome.

Could you do it in O(n) time and O(1) space?

/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
return true;
}
ListNode *p,*pre,*q;
pre=NULL;
while(q){
q=q->next;
if(!q){
break;
}
pre=p;
p=p->next;
q=q->next;
}
pre->next=NULL;
ListNode *r=reverse(p);
q=r;
while(p&&q){
if(p->val!=q->val){
return false;
}
p=p->next;
q=q->next;
}
return true;

}

ListNode *h=NULL;
ListNode *tail=NULL;
while(p){
ListNode *next=p->next;
p->next=NULL;
if(!h){
h=p;
}else{
p->next=h;
h=p;
}
p=next;
}
return h;
}
};

#### 234. Palindrome Linked List [easy] (Python)

2016-05-03 19:09:18

#### leetcode 234: Palindrome Linked List

2015-07-14 04:40:25

#### LeetCode 234: Palindrome Linked List （回文链表）

2015-07-16 22:48:30

2016-09-18 21:45:15

#### 【leetcode】234. Palindrome Linked List（Python & C++）

2017-09-02 20:15:34

2016-03-16 21:19:03

2015-07-29 11:40:29

#### (Leetcode 142)Linked List Cycle (II) (快慢指针详解)

2016-03-20 21:05:38

2016-05-22 09:14:23