LC 234. Palindrome Linked List

Nilanjan Deb · April 5, 2020

This is my CPP solution.

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


Dicussion Forum