LeetCode – Reverse Linked List II (Java)

Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Analysis Java Solution public ListNode reverseBetween(ListNode head, int m, int n) { if(m==n) return head;   ListNode prev = null;//track (m-1)th node ListNode first = new ListNode(0);//first’s … Read more