Skip to content

Latest commit

 

History

History
31 lines (28 loc) · 658 Bytes

83.remove-duplicates-from-sorted-list.md

File metadata and controls

31 lines (28 loc) · 658 Bytes

删除排序链表中的重复元素

题目

思路

链表为有序队列, 直接while对链表值的next进行循环判断即可

/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var deleteDuplicates = function(head) {
  let current = head
  while (current && current.next) {
    if (current.val === current.next.val) {
      current.next = current.next.next
    } else {
      current = current.next
    }
  }
  return head
};