My recursive C++ solution


  • 0
    N
    bool isPalindrome(ListNode* head) {
            
                return checkPalindrome(head,head);
        }
        bool checkPalindrome(ListNode*& head, ListNode* tail){     
            bool result;
            if( tail == NULL)
                return true;
            else
                 result = checkPalindrome( head, tail->next)
                             && head->val == tail->val; //compare value
            head = head->next; //advance pointer
            return result;
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.