Pointer of pointer


  • 0
    A
    class Solution {
    public:
        ListNode* insertionSortList(ListNode* head) {
            ListNode* ret = nullptr;
            while (head) {
                auto *pp=&ret, p=*pp;
                for (; p!=nullptr && p->val<head->val; pp=&p->next, p=*pp);
                *pp = head;
                head = (*pp)->next;
                (*pp)->next = p;
            }
            return ret;
        }
    };
    

Log in to reply
 

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