示例#1
0
#from mergeKLists import Solution
from bestDemo import Solution

from ListNode import ListNode

if __name__ == "__main__":
    sln = Solution()

    kLsts = ListNode.createLstLst([[1, 4, 5], [1, 3, 4], [2, 6]])

    tic = time.clock()
    lstRst = sln.mergeKLists(kLsts)
    toc = time.clock()
    expectRst = "1,1,2,3,4,4,5,6"
    print("TestCase1:",
          ListNode.printNode(lstRst) == expectRst,
          " —— take %.3f ms" % ((toc - tic) * 1000))

    kLsts = ListNode.createLstLst([[1, 4, 5, 11], [1, 3, 4], [2, 6], [6, 8, 9],
                                   [7]])

    tic = time.clock()
    lstRst = sln.mergeKLists(kLsts)
    toc = time.clock()
    expectRst = "1,1,2,3,4,4,5,6,6,7,8,9,11"
    print("TestCase2:",
          ListNode.printNode(lstRst) == expectRst,
          " —— take %.3f ms" % ((toc - tic) * 1000))

    with open('TestCase3.txt', 'r', encoding='utf-8') as f:
        for line in f.readlines():
示例#2
0
import time
from mergeTwoLists import Solution

from ListNode import ListNode

if __name__ == "__main__":
    sln = Solution()

    l1 = ListNode.createLst([1, 2, 4])
    l2 = ListNode.createLst([1, 3, 4])
    tic = time.clock()
    lstRst = sln.mergeTwoLists(l1, l2)
    toc = time.clock()
    expectRst = "1,1,2,3,4,4"
    print("TestCase1:", ListNode.printNode(lstRst) == expectRst, " —— take %.3f ms" % ((toc - tic) * 1000))