C# Solution by using a dummy node

  • 0
    public ListNode DeleteDuplicates(ListNode head) {
        ListNode dummy = new ListNode(0), pre = dummy;
        dummy.next = head;
        while(pre.next != null && pre.next.next != null)
            if(pre.next.val == pre.next.next.val)
                pre.next = pre.next.next;
            else pre = pre.next;
        return dummy.next;

Log in to reply

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