Skip to content

Instantly share code, notes, and snippets.

@lichray
Created March 24, 2017 22:35
Show Gist options
  • Save lichray/e438842297969f8e401b234832ce6844 to your computer and use it in GitHub Desktop.
Save lichray/e438842297969f8e401b234832ce6844 to your computer and use it in GitHub Desktop.
"Two star programming" with no star
#include <functional>
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
auto ls = std::ref(head);
while (ls != nullptr) {
if (ls.get()->val == val) {
auto p = ls.get();
ls.get() = p->next;
delete p;
}
else
ls = ls.get()->next;
}
return head;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment