simple c++ solution


  • 0
    H
    class Solution {
    public:
        ListNode* removeElements(ListNode* head, int val) {
            if(!head) return head;
            ListNode* cur = head;
            while(cur->next) {
                if(cur->next->val == val) cur->next = cur->next->next;
                else cur = cur->next;
            }
            return head->val == val ? head->next: head;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.