leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0203.cpp (372B)
0 class Solution { 1 public: 2 ListNode *removeElements(ListNode *head, int val) { 3 if (!head) return nullptr; 4 5 for (ListNode *p = head; p && p->next;) 6 if (p->next->val == val) 7 p->next = p->next->next; 8 else 9 p = p->next; 10 11 if (head->val == val) head = head->next; 12 13 return head; 14 } 15 };