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;
        }
    }
};

  

posted @ 2020-02-22 19:57  Somnuspoppy  阅读(120)  评论(0编辑  收藏  举报