/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
//若头指针与next所指val相同,跳过next,直接指向next.next
// if(head==null) {
// return head;
// }
// ListNode currentNode=head;
// while(currentNode.next!=null){
// if(currentNode.val==currentNode.next.val){
// currentNode.next=currentNode.next.next;
// }else{
// currentNode=currentNode.next;
// }
// }
// return head;
//递归法
if(head==null||head.next==null)
return head;
head.next=deleteDuplicates(head.next);
return head.val==head.next.val? head.next:head;
}
}