Double star programming, again

  • 0

    It seems this time it is easy to use double star.

    ListNode* swapPairs(ListNode* head) {
        if(!head || !head->next) return head;
        ListNode **back = &head;
        ListNode *front = head->next;
        while(1) {
            (*back)->next = front->next;
            front->next = *back;
            (*back) = front;
            back = &(front->next->next);
            front = front->next->next;
            if(!front) break;
            front = front->next;
            if(!front) break;
        return head;

Log in to reply

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