Created
April 4, 2017 14:36
-
-
Save s4553711/e96d47b6d1aca365cfe13aea9034ad93 to your computer and use it in GitHub Desktop.
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* removeElements(ListNode* head, int val) { | |
if (head == NULL) return head; | |
ListNode* h = new ListNode(0); | |
h->next = head; | |
ListNode* prev = h; | |
while(head != NULL) { | |
if (head->val == val) { | |
prev->next = head->next; | |
//delete c; | |
} else { | |
prev = head; | |
} | |
head = head->next; | |
} | |
return h->next; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment