var deleteDuplicates = function(head) {
var preHead = new ListNode(-1);
preHead.next = head;
var pre = preHead;
var cur = head;
while(cur !== null && cur.next !== null) {
if (pre.next.val !== cur.next.val) {
pre = pre.next;
cur = cur.next;
} else {
while (cur !== null && cur.next !== null && pre.next.val === cur.next.val) {
cur = cur.next
}
pre.next = cur.next;
cur = cur.next;
}
}
return preHead.next;
};
网友评论