c++ simple solution


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

Log in to reply
 

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