6 Line Clean Java Solution


  • -2
    M
    public ListNode deleteDuplicates(ListNode head) {
    
    		ListNode copyHead = head;
    		while (head != null) {
    			while (head.next != null && head.val == head.next.val) {
    				head.next = head.next.next;
    			}
    			head = head.next;
    		}
    		return copyHead;
    
    	}

  • 0
    T

    Why the downvotes? It's a very clean O(n) solution.


Log in to reply
 

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