Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

Leetcode Palindrome Linked List problem solution

YASH PAL, 31 July 202420 January 2026

In this Leetcode Palindrome Linked List problem solution, we have given the head of a singly linked list, return true if it is a palindrome.

Leetcode Palindrome Linked List problem solution

Leetcode Palindrome Linked List problem solution in Python.

class Solution(object):
    def isPalindrome(self, head):
        if not head:
            return True
        
        curr = head
        nums = []
        while curr:
            nums.append(curr.val)
            curr = curr.next
        
        left = 0
        right = len(nums) - 1
        
        while left <= right:
            if nums[left] != nums[right]:
                return False
            else:
                left += 1
                right -= 1
                
        return True

Palindrome Linked List problem solution in Java.

class Solution {
public boolean isPalindrome(ListNode head) {

    if (head == null || head.next == null) return true;
    
    Stack<Integer> stack = new Stack <Integer>();
    
    ListNode curr = head; 
    while (curr != null) {
        stack.push(curr.val);
        curr = curr.next;     
    }
   
    while (head != null) {
        if (stack.pop() != head.val) {
            return false;
        }
        else {
            head = head.next;
        }
    }
 
    return true;
}
}

Problem solution in C++.

class Solution {
public:
    bool isPalindrome(ListNode* head) {
        vector<int>tab;
        ListNode* p;
        p=head;
        while(p!=nullptr){
            tab.push_back(p->val);
            p=p->next;
        }
        int n=tab.size();
        for(int i=0;i<n/2;i++){
            if(tab[i]!=tab[n-i-1])return false;
        }
        return true;
    }
};

Problem solution in C.

bool isPalindrome(struct ListNode* head){
    if(head==NULL){
        return true;
    }
    struct ListNode* p1=head;
    struct ListNode* p2=head->next;
    while(p2 && p2->next){
        p1 = p1->next;
        p2 = p2->next->next;
    }
    
    struct ListNode *prev, *curr, *n, *h2;
    prev = NULL;
    curr = p1->next;
    h2 = curr;
    while(curr){
        n = curr->next;
        curr->next = prev;
        prev = curr;
        curr = n;
    }
    p2 = head;
    p1 = prev;
    while(p1){
        if(p1->val!=p2->val){
            return false;
        }
        p1 = p1->next;
        p2 = p2->next;
    }
    
    return true;

}

coding problems solutions Leetcode Problems Solutions Leetcode

Post navigation

Previous post
Next post

Leave a Reply

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

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes