public class Solution {

public ListNode reverseBetween(ListNode head, int m, int n) {

```
ListNode ln = head;
ListNode start = head;
int list_length = 0;
while(ln!=null){
list_length++;
ln = ln.next;
}
if(m<1||m>n||n>list_length){
return head;
}
int[] array = new int[list_length];
int i = 0;
ln = head;
while(ln != null){
array[i] = ln.val;
ln = ln.next;
i++;
}
for(int j = 0; j < m-1; j++){
start = start.next;
}
while(n >= m){
start.val = array[n-1];
start = start.next;
n--;
}
return head;
}
```

}