3 lines C++ iterative code.


  • 0
    J

    The code is contracted in 3 lines just for fun, may not be readable^-

    public:
        ListNode* deleteDuplicates(ListNode* head) {
            for(ListNode *p1 = head, *p2=NULL; p1 != NULL; p1 = p1->next = p2){
                for(p2 = p1->next; p2 != NULL && p2->val == p1->val; p2 = p2->next){}}
            return head;
        }
    };
    

Log in to reply
 

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