C++ solution


  • 0
    J
    class Solution {
    public:
        ListNode* removeElements(ListNode* head, int val) {
            while(head != NULL && head->val == val){
                head = head->next;
            }
            if(head == NULL) return NULL;
            
            ListNode* current = head;
            while(current != NULL){
                while(current->next != NULL && current->next->val == val){
                    current->next = current->next->next;
                }
                current = current->next;
            }
            return head;
        }
    };
    

Log in to reply
 

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