dsa · easy

Palindrome Linked List

You are given the head of a singly linked list. Return whether the sequence of node values is a **palindrome**. Empty list and a single node are palindromes.

Arguments

Walk .next on the ListNode.

Example

[1,2,2,1]true. [1,2]false.

Constraints

0 <= length <= 10^5 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[1,2,2,1]

Expected:
true

Example 2

Input:
[1,2]

Expected:
false

Open in the Dojo editor