true if the values form a palindrome (read the same forwards and backwards).Palindromic Linked List
L6 Medium Linked List
Concept
Because linked lists are only forward-accessible, checking symmetry usually means copying values into an array and using two indices.
Given the head of a singly linked list, return
Examples
▸ head = [1, 2, 2, 1]
→ true
▸ head = [1, 2]
→ false
▸ head = [1]
→ true
Progressive Hints
Hint 1 · Nudge
If you could read the list backwards it'd be trivial, so just copy it into something that supports both ends.
Hint 2 · Plan
Copy every value into an array, then compare from both ends inward, exactly like the word palindrome. Any mismatch means false.
Hint 3 · Approach
values = [], cur = head. While cur: append cur.val; cur = cur.next. Compare from both ends inward and return false on any mismatch.
All hints are out. Take a breath and give it a shot.
Output
// Run your code to see the output here.