# Solution to Q234: Determine Palindrome.

• ## Summary:

Use reverseList function to reverse the list from the middle of the given linked list.

## Example:

Suppose we have a linked list 1->2->3->2->0;

Firstly, reverse the list from the middle. Then we get two lists,

1. 1->2->3->2->1
2. 0->2

Second, compare the two lists from the beginning to half number of the original list. If there is a difference, return False. Otherwise, in the end, return True.

NOTE:

1. We need to consider odd length or even length.
2. This Algorithm runs in O(n) time and O(1) space.
``````class Solution {
public:
return NULL;

pre->next = NULL;
while(curr != NULL){
curr->next = pre;
pre = curr;
curr = post;
if(post != NULL)
post = post->next;

}
return pre;
}

int length = 0;
while(traversal != NULL){
traversal = traversal->next;
length++;
}
int half = length / 2;

if(length % 2 == 0){
while(half > 0){
traversal = traversal->next;
half--;
}

half = length / 2;

while(half > 0){
return false;
half--;
}
return true;
}
else{
while(half > 0){
traversal = traversal->next;
half--;
}
traversal = traversal->next;

half = length / 2;

while(half > 0){