why runtime error only one different


  • 0
    Y

    this is AC

    class Solution {
    public:
        ListNode* deleteDuplicates(ListNode* head) {
            ListNode* tmp = head;
            while(tmp!=NULL){
               # if(tmp->next!=NULL && tmp->val == tmp->next->val){
                    tmp->next = tmp->next->next;
                }else{
                    tmp = tmp->next;
                }
            }
            return head;
        }
    };
    

    this is runtime error . why ??

    class Solution {
    public:
        ListNode* deleteDuplicates(ListNode* head) {
            ListNode* tmp = head;
            while(tmp!=NULL){
                # if(tmp->val == tmp->next->val && tmp->next!=NULL ){
                    tmp->next = tmp->next->next;
                }else{
                    tmp = tmp->next;
                }
            }
            return head;
        }
    };
    

Log in to reply
 

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