My simple c++ solution


  • 0
    K
    class Solution {
    public:
    bool isPalindrome(ListNode* head) {
     ListNode * cur=head;
     vector<ListNode*>mylist;
        while(head)
        {
            mylist.push_back(head);
            head=head->next;
        }
        while(!mylist.empty())
        {
          
            if(cur->val!=mylist.back()->val)return false;
            mylist.pop_back();
            cur=cur->next;
        }
        return true;
        
    }
    

    };


Log in to reply
 

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