Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check if Linked List is Palindrome

Medium Acceptance 67.00% Points 30.00

You are given the head of a singly linked list. Your task is to determine whether the linked list forms a palindrome. Return true if it reads the same forward and backward; otherwise, return false.

Examples
Example 1

Example 1

Input: head = [1,2,2,1]

Output: true

Explanation: The linked list reads the same from left to right and right to left.

Example 2

Example 2

Input: head = [1,2,3,2,1]

Output: true

Explanation: The linked list is symmetric, so it is a palindrome.

Example 3

Example 3

Input: head = [1,2,3]

Output: false

Explanation: The linked list does not read the same in both directions.

Hints
Hint 1
N/A
Constraints
  • 1 = Number of nodes = 105
  • -10? = Node.data = 10?
Companies
Apple
Topics
Linked List
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions