leetcode-82-删除链表中重复元素2

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;

};

你可能感兴趣的:(leetcode-82-删除链表中重复元素2)