Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Given a singly linked list find if it is palindrome

Problem description :

Write a function to determine if a singly linked list is a palindrome.

Input : A linked list
Output : Boolean (true or false)

isPalindrome-min


Approach 1: Reverse and compare the linked lists.

Logic :

  • Create a new copy of the linked list.
  • Reverse the newly created linked list.
  • Compare the original linked list with the reversed linked list.

Time Complexity :

  • O(n) ; where n is the number of nodes in the linked list

This post is a follow-up of JavaScript Linked List Example and Reverse a singly linked list. I recommend reading that first, as the following code uses the method from it.

Solution :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *