public void Given_list_When_reserse_1_1_Then_return() { var root = new ListNode(1) { }; var result = ReverseLinkedListII.ReverseBetween(root, 1, 1); Assert.AreEqual(1, result.val); }
public void Example6() { var sol = new ReverseLinkedListII(); var list = new ListNode( 1, new ListNode(2, new ListNode(3))); var reversed = sol.ReverseBetween(list, 2, 4); Assert.AreEqual("1, 3, 2", reversed.ToString()); }
public void Example2() { var sol = new ReverseLinkedListII(); var list = new ListNode( 1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5))))); var reversed = sol.ReverseBetween(list, 6, 7); Assert.AreEqual("1, 2, 3, 4, 5", reversed.ToString()); }
public void Given_list_When_reserse_2_4_Then_return() { var root = new ListNode(1) { next = new ListNode(2) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) } } } }; var result = ReverseLinkedListII.ReverseBetween(root, 2, 4); Assert.AreEqual(1, result.val); Assert.AreEqual(4, result.next.val); }
public void ReverseBetweenTests() { ReverseLinkedListII obj = new ReverseLinkedListII(); var node = new ListNode(1) { next = new ListNode(2) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) { } } } } }; //1 2 3 4 5 -> 1 4 3 2 5 var x = obj.ReverseBetween(node, 2, 4); node = new ListNode(1) { next = new ListNode(2) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) { next = new ListNode(6) { next = new ListNode(7) { } } } } } } }; //1 2 3 4 5 6 7 -> 1 2 3 4 5 6 7 x = obj.ReverseBetween(node, 1, 1); node = new ListNode(1) { next = new ListNode(2) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) { next = new ListNode(6) { next = new ListNode(7) { } } } } } } }; //1 2 3 4 5 6 7 -> 7 6 5 4 3 2 1 x = obj.ReverseBetween(node, 1, 7); node = new ListNode(1) { next = new ListNode(2) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) { next = new ListNode(6) { next = new ListNode(7) { } } } } } } }; //1 2 3 4 5 6 7-> 1 2 3 4 5 7 6 x = obj.ReverseBetween(node, 6, 7); node = new ListNode(1) { next = new ListNode(2) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) { next = new ListNode(6) { next = new ListNode(7) { } } } } } } }; //1 2 3 4 5 6 7 -> 2 1 3 4 5 6 7 x = obj.ReverseBetween(node, 1, 2); node = new ListNode(1) { }; x = obj.ReverseBetween(node, 1, 1); node = new ListNode(1) { }; x = obj.ReverseBetween(node, 1, 1); node = new ListNode(1) { next = new ListNode(2) { } }; x = obj.ReverseBetween(node, 1, 2); }