@@ -0,0 +1,1748 @@
+// Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.%0A%0A// If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.%0A%0A// You may not alter the values in the nodes, only nodes itself may be changed.%0A%0A// Only constant memory is allowed.%0A%0A// For example,%0A// Given this linked list: 1-%3E2-%3E3-%3E4-%3E5%0A%0A// For k = 2, you should return: 2-%3E1-%3E4-%3E3-%3E5%0A%0A// For k = 3, you should return: 3-%3E2-%3E1-%3E4-%3E5%0A%0A/**%0A * Definition for singly-linked list.%0A * public class ListNode %7B%0A *     int val;%0A *     ListNode next;%0A *     ListNode(int x) %7B%0A *         val = x;%0A *         next = null;%0A *     %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A    public ListNode reverseKGroup(ListNode head, int k) %7B%0A        if(k %3C= 1 %7C%7C head == null %7C%7C head.next == null) return head;%0A%0A        ListNode fake = new ListNode(0);%0A        fake.next = head;%0A%0A        ListNode runner = fake;%0A%0A        while(runner != null)%7B%0A        %09ListNode tmpRunner = runner;%0A        %09int counter = 0;%0A        %09while(counter %3C k && tmpRunner != null)%7B%0A        %09%09counter++;%0A        %09%09tmpRunner = tmpRunner.next;%0A        %09%7D%0A        %09if(counter != k %7C%7C tmpRunner == null) break;%0A%0A        %09ListNode start = runner.next;%0A%0A        %09runner.next = reverse(start, tmpRunner);%0A%0A        %09for(int i = 0; i %3C k; i++)%7B%0A        %09%09runner = runner.next;%0A        %09%7D%0A        %7D%0A%0A        return fake.next;%0A    %7D%0A%0A    public ListNode reverse(ListNode start, ListNode end)%7B%0A    %09ListNode finalEnd = end.next;%0A    %09ListNode pre = start;%0A    %09ListNode curr = start.next;%0A%0A    %09while(curr != finalEnd)%7B%0A    %09%09ListNode next = curr.next;%0A    %09%09curr.next = pre;%0A    %09%09pre = curr;%0A    %09%09curr = next;%0A    %09%7D%0A    %09start.next = finalEnd;%0A    %09return end;%0A    %7D%0A%7D

add reverse nodes in k group