Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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) {
- ListNode *current = NULL;
- ListNode *anterior = NULL;
- current = head;
- while(current){
- if(anterior != NULL && current->val == anterior->val){
- anterior->next = current->next;
- }else anterior = current;
- current = current->next;
- }
- return head;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement