Linked listsAnimated
Palindrome Linked List
Reverse the second half and compare it with the first.
Time
O(n)
Extra space
O(1)
Use it for
Checking symmetry in place.
How it works
- Find the middle with slow/fast pointers.
- Reverse the second half of the list in place.
- Walk from the head and from the start of the reversed half together, comparing values.
- If every pair matches it is a palindrome. O(n) time, O(1) memory.
Watch it run
Loading animation…