코테준비 - Remove Duplicates from Sorted List

정상화·2023년 2월 26일

LeetCode

목록 보기
80/222

Remove Duplicates from Sorted List

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        auto fix = head;
        if(fix == nullptr) return nullptr;
        for (auto cursor = head->next; cursor != nullptr; cursor = cursor->next) {
            if (fix->val != cursor->val) {
                fix->next = cursor;
                fix = cursor;
            }
        }
        fix->next = nullptr;
        return head;
    }
};
profile
백엔드 희망

0개의 댓글