LeetCode 24 两两交换链表中的节点
生活随笔
收集整理的這篇文章主要介紹了
LeetCode 24 两两交换链表中的节点
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
https://leetcode-cn.com/problems/swap-nodes-in-pairs/、
解決方案
class Solution {public ListNode swapPairs(ListNode head) {if (head != null && head.next != null) {ListNode node = head.next;head.next = swapPairs(head.next.next);node.next = head;return node;}return head;} }總結(jié)
以上是生活随笔為你收集整理的LeetCode 24 两两交换链表中的节点的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 23 合并K个升序链表
- 下一篇: LeetCode 25 K个一组翻转链表