83. Remove Duplicates from Sorted List
Input: 1->1->2
Output: 1->2Input: 1->1->2->3->3
Output: 1->2->3解题要点:
/**
* 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;
}
}Last updated