二级指针


  • 0
    Z

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


  • 0
    2

    "If you want to include code in your post, please surround your code block with 3 backticks ```"

    translation:
    如果你想在你的帖子中包含代碼,請用3個反引號 ```來圍起你的代碼


Log in to reply
 

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