예제 #1
0
def test_2():
    test = Solution2()
    l1 = ListNode(9)
    l1.next = ListNode(8)

    l2 = ListNode(1)

    x =  test.addTwoNumbers(l1,l2)
    while x != None:
        print x.val
        x = x.next
예제 #2
0
def test_24():
    x = Solution024()

    a1 = ListNode(1)
    a2 = ListNode(3)
    a3 = ListNode(5)
    a4 = ListNode(7)
    a1.next = a2
    a2.next = a3
    a3.next = a4
    a4.next = None

    x.swapPairs(a1)
예제 #3
0
def test_25():

    a1 = ListNode(1)
    a2 = ListNode(2)
    a3 = ListNode(3)
    a4 = ListNode(4)
    a5 = ListNode(5)
    a1.next = a2
    a2.next = a3
    a3.next = a4
    a4.next = a5

    a6 = ListNode(6)
    a5.next = a6
    a7 = ListNode(7)
    a6.next = a7

    x = Solution025()
    y = x.reverseKGroup(a1, 3)

    while y:
        print y.val
        y = y.next
예제 #4
0
def test_23():
    x = Solution023()

    a1 = ListNode(1)
    a2 = ListNode(3)
    a3 = ListNode(5)
    a1.next = a2
    a2.next = a3
    a3.next = None

    b1 = ListNode(0)
    b2 = ListNode(4)
    b3 = ListNode(6)
    b1.next = b2
    b2.next = b3
    b3.next = None

    c1 = ListNode(2)
    c2 = ListNode(5)
    c3 = ListNode(8)
    c1.next = c2
    c2.next = c3
    c3.next = None

    x.mergeKLists([a1, b1, c1])
예제 #5
0
def test_21():
    a1 = ListNode(1)
    a2 = ListNode(3)
    a3 = ListNode(5)
    a1.next = a2
    a2.next = a3

    b1 = ListNode(0)
    b2 = ListNode(4)
    b3 = ListNode(6)
    b1.next = b2
    b2.next = b3

    x = Solution021()
    y = x.mergeTwoLists(a1, None)
    assert y.next.val == 3

    a1 = ListNode(1)
    a2 = ListNode(3)
    a3 = ListNode(5)
    a1.next = a2
    a2.next = a3
    a3.next = None

    b1 = ListNode(0)
    b2 = ListNode(4)
    b3 = ListNode(6)
    b1.next = b2
    b2.next = b3
    b3.next = None
    y = x.mergeTwoLists(a1, b1)
    assert y.next.val == 1

    a1 = ListNode(1)
    a2 = ListNode(3)
    a3 = ListNode(5)
    a1.next = a2
    a2.next = a3
    a3.next = None

    b1 = ListNode(0)
    b2 = ListNode(4)
    b3 = ListNode(6)
    b1.next = b2
    b2.next = b3
    b3.next = None
    y = x.mergeTwoLists(None, b1)
    assert y.next.val == 4
예제 #6
0
def test_19():
    first = ListNode(1)
    second = ListNode(2)
    third = ListNode(3)
    fourth = ListNode(4)
    fifth = ListNode(5)

    first.next = second
    second.next = third
    third.next = fourth
    fourth.next = fifth

    x = Solution19()
    y = x.removeNthFromEnd(first, 2)
    assert y.val == 1
    assert y.next.val == 2
    assert y.next.next.val == 3
    assert y.next.next.next.val == 5

    x.removeNthFromEnd(None, 0)

    first = ListNode(1)
    second = ListNode(2)
    first.next = second

    x.removeNthFromEnd(first, 2)