Palindrome Linked List

Question (LC.234)

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

Example

I: 1 -> 2 -> 1
O: true

Analysis

Need to use L/R pointers to compare the first half and the second half.

Approach

Step 1 Find the mid point
Step 2 reverse the second half
Step 3 compare two lists
Step 4 (optional) reverse the second half back

Code

Last updated