leetcode【 24 两两交换链表中的节点】

在这里插入图片描述

struct ListNode* swapPairs(struct ListNode* head) {
    
    
    if (head == NULL || head->next == NULL) {
    
    
        return head;
    }
    struct ListNode* newHead = head->next;
    head->next = swapPairs(newHead->next);
    newHead->next = head;
    return newHead;
}

猜你喜欢

转载自blog.csdn.net/qq_45657288/article/details/109063078