leetcode 24. 两两交换链表中的节点

leetcode 24. 两两交换链表中的节点,第1张

又是递归

class Solution {
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        
        ListNode temp = head.next;
        head.next = swapPairs(temp.next);
        temp.next = head;
        return temp;
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/919413.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存