Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 509 Bytes

0083-删除排序链表中的重复元素.md

File metadata and controls

29 lines (24 loc) · 509 Bytes

给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。

示例 1:

输入: 1->1->2 输出: 1->2 示例 2:

输入: 1->1->2->3->3 输出: 1->2->3

var deleteDuplicates = function(head) {
  if (!head) {
    return head
  }
  let current = head
  while(current && current.next) {
    if (current.val === current.next.val) {
      current.next = current.next.next
      continue
    }
    current = current.next
  }
  return head
};

解题思路:简单的题目