[leetcode 24] Swap Nodes in k-Group

1 题目:

目前被墙,看不了。

2 思路:

比较简单,注意处理边界点就好

3 代码:

    public ListNode swapPairs(ListNode head) {
        int temp;
        if(head == null){
            return null;
        }
        
        ListNode h = head;
        while(h != null){
            ListNode node = h.next;
            if(node!=null){
                temp = h.val;
                h.val = node.val;
                node.val = temp;
                h = h.next;
            }
            h = h.next;
        }
        
        return head;
    }

注意处理奇数个的时候。

原文地址:https://www.cnblogs.com/lingtingvfengsheng/p/4812468.html