Java iterative, clean code.


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

Log in to reply
 

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