Linked List Palindrome - aloalgo

Linked List Palindrome

Medium

You are given the head of a singly linked list.

Your task is to determine whether the values in the linked list form a palindrome.

Note that:

  • An empty linked list is considered a palindrome.

Return true if the linked list is a palindrome, and false otherwise.

Example 1

Input
1 → 2 → 3 → 2 → 1 → null
Output
True
Explanation:

The values read the same forwards and backwards: 1, 2, 3, 2, 1.

Example 2

Input
1 → 2 → 3 → 4 → null
Output
False
Explanation:

The values 1, 2, 3, 4 do not read the same forwards and backwards.

Example 3

Input
1 → null
Output
True
Explanation:

A single-node linked list is always a palindrome.

Loading...
Input
1 → 2 → 3 → 2 → 1 → null
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!