# Straight forward 1ms Java O(n) Solution without extra space, but with comments ;-)

• `````` /**
* Since the original linked list will be divided into n/k portions which need to be reversed
* plus the left over portion which does not need to be reversed
* So basically my idea is to find those reversion needed portions and reverse them sequentially
* then link them all and return the modified list at last
*/
public static ListNode reverseKGroup(ListNode head, int k) {
if(head == null || head.next == null || k == 1){ //handle edge cases
}

int index = 1;
ListNode previousPortionTail = head; //after each reversion, head of each portion will become the tail of each portion

while(index <= k && pointer != null){ //find the first portion
pointer = pointer.next;
index++;
}

if(pointer == null && index <=k) // if k is bigger than the list size, just return origin list

ListNode nextStart = pointer;
ListNode toReturn = advancedReverseList(head,nextStart); //reverse first portion of the original list, the boundary of it will be nothing but the next portion's start node

while(pointer != null){ //keep looping the list
if(index % k == 0){ //reverse the following portion of the original list
ListNode boundary = pointer.next;
previousPortionTail = nextStart; // update the tail of the previous portion
nextStart = boundary; //set the start node of the next portion
pointer = nextStart;
}else{
pointer = pointer.next;
}
index++;
}
}

/**
* similar to ordinary reverse linked list method, but additionally check if node reaches the boundary node
* and append boundary node to the end of the reversed linked list.
*/
if(boundary != null) {
}
}else{