标签:
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
LL基本操作:每次判断p.val与p.next.val是否相等,若相等则直接连接下一个node,若相等则移后指针。
var deleteDuplicates = function(head) { if(!head) return null var dummy = new ListNode() dummy.next = head var p = head while(p.next) if(p.val===p.next.val) p.next = p.next.next else p = p.next return dummy.next }
Leetcode 83 Remove Duplicates from Sorted List
标签:
原文地址:http://www.cnblogs.com/lilixu/p/4603576.html