PIXELBANKv8.2.1
Menu

Palindrome Linked List

Given a linked list (as comma-separated values), return True if it is a palindrome.

Example:

Input:
1,2,2,1
Output:
True
Reasoning:
  • The input linked list is 1,2,2,1, which can be visualized as a sequence of nodes with values 12211 \rightarrow 2 \rightarrow 2 \rightarrow 1.
  • To check if it's a palindrome, we compare the first and last nodes, then the second and second-to-last nodes, and so on.
  • Since the values are symmetric (1=11 = 1 and 2=22 = 2), the linked list is a palindrome.
  • The function returns True because the input linked list reads the same backward as forward.

Constraints:

  • 1 <= number of nodes <= 10^5
  • 0 <= Node.val <= 9
Editor

Test Results

0/0
Run code to see test results.