Palindrome Linked List

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

Example

Example 1:

Input:
 1->2

Output:
 false

Example 2:

Input:
 1->2->2->1

Output:
 true

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

Note

找中点+reverse+两个头指针比较

Code

Last updated