Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
For example,
Given this linked list: 1->2->3->4->5
For k = 2, you should return: 2->1->4->3->5
For k = 3, you should return: 3->2->1->4->5
先计算长度,再分组,每组中node翻转,翻转用交换收尾方法
package pack;
class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
class Solution {
public ListNode reverseKGroup(ListNode head, int k) {