83. 删除排序链表中的重复元素(Java递归实现)_java

/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if (head == null || head.next == null) return head;

head.next = deleteDuplicates(head.next);

return head.val == head.next.val ? head.next : head;
}
}