/* * @lc app=leetcode id=25 lang=java * * [25] Reverse Nodes in k-Group */ // @lc code=start /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode reverseKGroup(ListNode head, int k) { ListNode dummy = new ListNode(0), prev, frm, to; dummy.next = head; prev = dummy; while(prev.next != null) { frm = to = prev.next; for(int i = 0; i