Help me with this code issue
ListNode* mid_ele(ListNode* head){
        ListNode* slow=head;
        ListNode* fast=head;
        while(fast!=NULL && fast->next!=NULL){
            slow=slow->next;
            fast=fast->next->next;
        }
        return slow;
    }
    ListNode* reverse(ListNode* head){
        ListNode* prev=NULL;
        ListNode* curr=head;
        ListNode* temp=NULL;
        while(curr!=NULL){
            temp=curr->next;
            curr->next=prev;
            prev=curr;
            curr=temp;
        }
        return head;
    }
    bool isPalindrome(ListNode* head) {
        if(head==NULL){
            return true;
        }
        ListNode* mid=mid_ele(head);
        ListNode* last=reverse(mid->next);
        ListNode* curr=head;
        while(last!=NULL){
            if(last->val!=curr->val){
                return false;
            }
            last=last->next;
            curr=curr->next;
        }
        return true;
    }
my code is failing for some test case like[1,2]
can anyone tell me whats wrong with my code
Comments (0)