#234
Easy Algorithms Palindrome linked list
Linked List Two Pointers Stack Recursion
57.5% acceptance
Jan 12, 2026
18221
974
Given the head of a singly linked list, return true if it is a palindrome or false otherwise.
Solution
Rust
Time O(n)
Space O(n)
impl Solution {
pub fn is_palindrome(head: Option<Box<ListNode>>) -> bool {
let mut vals = Vec::new();
let mut curr = &head;
while let Some(node) = curr {
vals.push(node.val);
curr = &node.next;
}
vals == vals.iter().rev().copied().collect::<Vec<_>>()
}
}