leetcode 24 Swap Nodes in Pairs

2018-06-04 11:59:55 浏览数 (2)

代码语言:javascript复制
class Solution {
public:
    ListNode* swapPairs(ListNode* head) {
        if (!head || !head->next) return head;
        ListNode *t = head->next;
        head->next = swapPairs(head->next->next);
        t->next = head;
        return t;
    }
};

0 人点赞