public static void main(String[] args) { // TODO Auto-generated method stub ReverseLinkedListII rList = new ReverseLinkedListII(); ListNode p1 = new ListNode(3); ListNode p2 = new ListNode(5); ListNode p3 = new ListNode(4); p1.next = p2; p2.next = p3; rList.reverseBetween(p1, 1, 2); }
public static void main(String[] args) { int[] vs = {9, 8, 7, 6, 5}; int m = 2, n = 3; ListNode head = null, runner = null; for (int v : vs) { if (head == null) { head = new ListNode(v); runner = head; } else { runner.next = new ListNode(v); runner = runner.next; } } ReverseLinkedListII o = new ReverseLinkedListII(); runner = o.reverseBetween(head, m, n); while (runner != null) { System.out.print(runner.val + " "); runner = runner.next; } }