You are given the head of a singly linked list. Your task is to determine whether the linked list forms a palindrome. Return true if it reads the same forward and backward; otherwise, return false.
Example 1
Input: head = [1,2,2,1]
Output: true
Explanation: The linked list reads the same from left to right and right to left.
Example 2
Input: head = [1,2,3,2,1]
Output: true
Explanation: The linked list is symmetric, so it is a palindrome.
Example 3
Input: head = [1,2,3]
Output: false
Explanation: The linked list does not read the same in both directions.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1 2 2 1
true
1 2 3 4
false
1 2 3 2 1
true