Search
 
SCRIPT & CODE EXAMPLE
 

CPP

remove duplicates from sorted list solution in c++

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

PREVIOUS NEXT
Code Example
Cpp :: cout in c++ 
Cpp :: ue4 c++ switch enum 
Cpp :: how to compile c++ code with g+ 
Cpp :: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ 
Cpp :: front priority queue cpp 
Cpp :: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope 
Cpp :: java to puthon converter 
Cpp :: using-controller-and-qt-worker-in-a-working-gui-example 
Cpp :: c++ convert int to string with a fixed number of digits 
Cpp :: Write a C++ program to Computing Mean and Median Using Arrays 
Cpp :: remove item from layout 
Cpp :: Vaccine Dates codechef solution in c++ 
Cpp :: c++ to c converter tool 
Cpp :: fabs c c++ 
Cpp :: what is c++ 
Cpp :: kruskal algorithm 
Cpp :: error when using base class members 
Cpp :: long, long long 32 bit or 8 bit in c++ 
Cpp :: properties of loop in c++ and how it works 
Cpp :: tu hi hai aashiqui song lyrics 
Cpp :: destiny child 
Cpp :: number of characters in string 
Cpp :: sleep function i nc++ 
Cpp :: how to compile with libstdc++ fedora 
Cpp :: Temporary file using MSFT API in cpp 
Cpp :: libraries required for gaming in c++ 
Cpp :: inorder to postorder converter online 
Cpp :: find the mminimum of the vector and its position in c++ 
Cpp :: 271533778232847 
Cpp :: glm multiply vector by scalar 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =