1,正常做 //执行用时 : 2 ms, 在Reverse Nodes in k-Group的Java提交中击败了88.82% 的用户 //内存消耗 : 40 MB, 在Reverse Nodes in k-Group的Java提交中击败了46.14% 的用户 class Solution { public ListNode reverseKGroup(ListNode head, int k) { //先处理空链表,单节点链表 //k=1,不用处理,直接返回 if(head == null || head.next == null || k <= 1) return head; //dummyhead,维持初始位置 ListNode dummyhead = new ListNode(-1); ListNode pre; ListNode temp; ListNode[] list = new ListNode[k]; int total = 0; temp = head; //计算总长和循环次数 while(temp != null){ ++total; temp = temp.next; } int n = total/k; //temp回到head位置 temp = head; //初始化dummyhead位置 dummyhead.next = head; //初始化pre pre = dummyhead; int x = 1; int j; //在whie循环外声明j,会使得内存占用变高,38.5 ->40m while(x <= n){ j = 0; //拿到k个节点 for (;j