📘
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 1→2→2→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=1 and 2=2), the linked list is a palindrome.
- The function returns
Truebecause the input linked list reads the same backward as forward.
Constraints:
- 1 <= number of nodes <= 10^5
- 0 <= Node.val <= 9
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.