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;
}
25. Reverse Nodes in k-Group
最新推荐文章于 2024-08-06 17:50:14 发布