LeetCode 83. Remove Duplicates from Sorted List(从有序链表中删除重复节点)

题意:从有序链表中删除重复节点。

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

  

猜你喜欢

转载自www.cnblogs.com/tyty-Somnuspoppy/p/12346857.html