Leetcode83.Remove_Duplicates_From_Sorted_List

排序过的链表,顺序遍历就ok
时间复杂度:O(N)
C++代码:

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* record = head;
        while(head != nullptr && head->next != nullptr)
        {
            if(head->val == head->next->val)
            {
                head->next = head->next->next;
            }
            else
            {
            head = head->next;
            }
        }
        return record;
    }
};

猜你喜欢

转载自blog.csdn.net/qq_42263831/article/details/82777109