My foolish way to solve it


  • -1
    D
    bool isPalindrome(ListNode* head) {
        ListNode* p1=head;
        ListNode* front=head;
        string strfront,strmiddle;
        int count=0;
        int temp=0;
        while(p1){
            count++;
            p1=p1->next;
        }
        while(temp<count){
            if(temp<count/2){
                strfront=to_string(front->val)+strfront;
                front=front->next;
                temp++;
            }
            else if((count%2)&&(temp==count/2)){
                front=front->next;
                temp++;
            }
            else{
                strmiddle=strmiddle+to_string(front->val);
                front=front->next;
                temp++;
            }
        }
        if(strfront==strmiddle)
            return true;
        else
            return false;
        }

  • -1
    S
    This post is deleted!

Log in to reply
 

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