Created
December 10, 2016 17:41
-
-
Save terracotta-ko/6d20ce052e9f82ba514aab5919a5f3d6 to your computer and use it in GitHub Desktop.
gist for leetcode 83
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
return NULL; | |
} | |
ListNode *prv = head; | |
ListNode *curr = head->next; | |
while(curr) { | |
if(curr->val > prv->val) { | |
prv->next = curr; | |
prv = curr; | |
} | |
curr = curr->next; | |
} | |
prv->next = curr; | |
return head; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment