解法1:
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(null==head){
return null;
}
ListNode phead=head;
while(null!=phead.next){
if(phead.next.val==phead.val){
phead.next=phead.next.next;
}else{
phead=phead.next;
}
}
return head;
}
}
解法2:递归
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(null==head ||null ==head.next){
return head;
}
head.next=deleteDuplicates(head.next);
return head.val==head.next.val?head.next:head;
}
}