leetcode 234 Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.
Follow up:
Could you do it in O(n) time and O(1) space?
- using two pointers:
- A
slow
pointer with step length equals One - A
fast
pointer with step length eauqls Two
- A
- We can get the middle elements pointed by slow when the total number of the array is odd.
Slow
pointer points at the larger one when the array is at a length of even.- We can implements an function which reverses the linked list, So we can get the reverse list over [slow, -1].
- compare
head
withslow
step by step untilslow
points to null.
1 | /** |