c#(sharp) solution - simple to understand and beat 80%


  • 0
            public static ListNode DeleteDuplicates(ListNode head)
            {
                if (head == null) return null;
                ListNode pointer = head;
                while (pointer.next != null)
                {
                    if (pointer.next.val == pointer.val)
                    {
                        pointer.next = pointer.next.next;
                    }
                    else
                    {
                        pointer = pointer.next;
                    }
                }
                return head;
            }
    

Log in to reply
 

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