我是靠谱客的博主 隐形戒指,这篇文章主要介绍力扣(四),现在分享给大家,希望可以做个参考。

24.两两交换链表

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
 var swapPairs = function(head) {
    let dummy = new ListNode();
    dummy.next = head;
    let current = dummy;
    while(current.next !==null &&current.next.next !==null){
        let n1 = current.next;
        let n2 = current.next.next;
        current.next = n2;
        n1.next=n2.next;
        n2.next = n1;
        current=n1;
    }
    return dummy.next;
};

最后

以上就是隐形戒指最近收集整理的关于力扣(四)的全部内容,更多相关力扣(四)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部