Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

两两交换链表中的节点 #291

Open
Sunny-117 opened this issue Nov 8, 2022 · 1 comment
Open

两两交换链表中的节点 #291

Sunny-117 opened this issue Nov 8, 2022 · 1 comment

Comments

@Sunny-117
Copy link
Owner

No description provided.

@lxy-Jason
Copy link
Contributor

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var swapPairs = function(head) {
    if(!head || !head.next){
        return head;
    }
    const newHead = head.next; //第二个节点
    head.next = swapPairs(newHead.next); //把第三个节点传入,返回的是第四个节点
    newHead.next = head;//第一个节点接在第二节点之后
    return newHead
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants