25. Reverse Nodes in k-Group

来源:互联网 发布:淘宝缴费 编辑:程序博客网 时间:2024/05/30 02:25
public static ListNode reverseKGroup(ListNode head, int k) {        int[] a = new int[k];        int count = 0;        ListNode pre = head, cur = head;        while(cur != null) {            a[count] = cur.val;            count++;            if(count == k) {                int j = k-1;                while(pre !=null && j >=0) {                    pre.val = a[j--];                    pre = pre.next;                }                count = 0;            }            cur = cur.next;        }        return head;    }
0 0