public ListNode deleteDuplicates(ListNode head) {
// Start typing your Java solution below
// DO NOT write main() function
if(head == null) return head;
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode previous = dummy;
ListNode current = head;
while(current != null) {
int tmp = current.val;
if(current.next != null && current.next.val == tmp) {
while(current != null && current.val == tmp) {
current = current.next;
previous.next = current;
}
}else {
previous = current;
current = current.next;
}
}
return dummy.next;
}
Remove Duplicates from Sorted List II
最新推荐文章于 2018-10-27 15:22:26 发布