83. Remove Duplicates from Sorted List
1 public ListNode deleteDuplicates(ListNode head) { 2 if(head == null) { 3 return null; 4 } 5 ListNode dummy = new ListNode(-1); 6 dummy.next = head; 7 while(head != null && head.next != null) { 8 if(head.val == head.next.val) { 9 head.next = head.next.next; 10 } else { 11 head = head.next; 12 } 13 } 14 return dummy.next; 15 }
第10行是else,不是每次执行,这样连续重复数字才能被处理