leetcode第234题，简单链表操作的题目，题目要求判断给定的单链表是否是回文的，是返回true，否则返回false。

c++代码：

```class Solution {
public:
{

//找中点
while(fast->next != NULL && fast->next->next != NULL)
{
fast = fast->next->next;
slow = slow->next;
}

bool isOdd = true;
if (fast->next == NULL)isOdd = false;

if (!isOdd)fast = slow;
else fast = slow->next;

//将前半部分逆置
ListNode *pre = new ListNode(-1);
pre->next = fast;
while(slow != fast)
{
ListNode *t = slow->next;
slow->next = pre->next;
pre->next = slow;
slow = t;
}

//前后两部分比较
slow = pre->next;
bool isPalindrome = true;
if (!isOdd)fast = fast->next;
while(fast != NULL)
{
if (slow->val != fast->val)
{
isPalindrome = false;
break;
}
slow = slow->next;
fast = fast->next;
}
return isPalindrome;
}
};
```

python代码：

```class Solution(object):
"""
:rtype: bool
"""
#找中点
return True
while fast.next != None and fast.next.next != None:
fast = fast.next.next
slow = slow.next

isOdd = True
if fast.next == None:
isOdd = False

if isOdd:
fast = slow.next
else:
fast = slow
#前半部分逆置
pre = ListNode(-1)
pre.next = fast
while slow != fast:
t = slow.next
slow.next = pre.next
pre.next = slow
slow = t

#判断是否是回文
if not isOdd:
fast = fast.next

slow = pre.next
isPalindrome = True
while fast != None:
if fast.val != slow.val:
isPalindrome = False
break
fast = fast.next
slow = slow.next
return isPalindrome
```