當前位置: 首頁>>代碼示例>>Python>>正文


Python btNode.BTNode類代碼示例

本文整理匯總了Python中btNode.BTNode的典型用法代碼示例。如果您正苦於以下問題:Python BTNode類的具體用法?Python BTNode怎麽用?Python BTNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了BTNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test2

def test2():
    #rslt = buildUniqueBST(4)
    rslt = buildBST_dp(4)
    for t in rslt:
        BTNode.print_nodes(t)
        print('--------------')
    print('==============')
開發者ID:victorfei,項目名稱:interview,代碼行數:7,代碼來源:buildUniqueBST.py

示例2: test2

def test2():
    n1 = BTNode(1)
    n2 = BTNode(2)

    n1.left = n2
    print(pathSum(n1, 0, 1))
    print(pathSumAlt(n1, 1))
開發者ID:victorfei,項目名稱:interview,代碼行數:7,代碼來源:sumPath.py

示例3: buildTHelper

def buildTHelper(post_o, in_o, idx_dic, beg, end):
    if beg < end:
        mid = idx_dic[post_o.pop()]
        n = BTNode(in_o[mid])
        n.right = buildTHelper(post_o, in_o, idx_dic, mid+1, end)
        n.left = buildTHelper(post_o, in_o, idx_dic, beg, mid)

        return n
開發者ID:victorfei,項目名稱:interview,代碼行數:8,代碼來源:buildTreePostInorder.py

示例4: test1

def test1():
    n5 = BTNode(5)
    n2 = BTNode(2)
    nm3 = BTNode(-3)

    n5.left = n2
    n5.right = nm3

    print(mfss(n5))
開發者ID:victorfei,項目名稱:interview,代碼行數:9,代碼來源:mostFreqSubtreeSum.py

示例5: test2

def test2():
    n5 = BTNode(5)
    n2 = BTNode(2)
    nm5 = BTNode(-5)

    n5.left = n2
    n5.right = nm5

    print(mfss(n5))
開發者ID:victorfei,項目名稱:interview,代碼行數:9,代碼來源:mostFreqSubtreeSum.py

示例6: test2

def test2():
    post_o = [2, 1]
    in_o = [2, 1]
    BTNode.print_nodes(buildT(post_o, in_o))

    print('-----------------------------')
    post_o = [2, 1]
    in_o = [2, 1]
    BTNode.print_nodes(buildT(post_o, in_o))
開發者ID:victorfei,項目名稱:interview,代碼行數:9,代碼來源:buildTreePostInorder.py

示例7: buildT

def buildT(post_o, in_o):
    """
    68% percentile in leetcode
    """
    if in_o:
        mid = in_o.index(post_o.pop())
        n = BTNode(in_o[mid])
        n.right = buildT(post_o, in_o[mid+1:])
        n.left = buildT(post_o, in_o[:mid])

        return n
開發者ID:victorfei,項目名稱:interview,代碼行數:11,代碼來源:buildTreePostInorder.py

示例8: test1

def test1():
    rslt = buildUniqueBST(3)
    for t in rslt:
        BTNode.print_nodes(t)
        print('--------------')
    print('==============')
    rslt = buildBST_dp(3)
    for t in rslt:
        BTNode.print_nodes(t)
        print('--------------')
    print('==============')
開發者ID:victorfei,項目名稱:interview,代碼行數:11,代碼來源:buildUniqueBST.py

示例9: constructTree

def constructTree(arr):
    if not arr: return None

    idx = findMax(arr)
    n = BTNode(arr[idx])
    lhs = constructTree(arr[:idx])
    rhs = constructTree(arr[idx+1:])
    n.left = lhs
    n.right = rhs

    return n
開發者ID:victorfei,項目名稱:interview,代碼行數:11,代碼來源:maxBinaryTree.py

示例10: test2

def test2():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n3 = BTNode(3)
    n4 = BTNode(4)

    n1.left = n2
    n2.right = n4
    n1.right = n3
    print(constructStr(n1))
    print(constructStr2_top(n1))
開發者ID:victorfei,項目名稱:interview,代碼行數:11,代碼來源:stringFromBinaryTree.py

示例11: ll2tfaster_dfs2

    def ll2tfaster_dfs2(self, beg, end):
        if beg > end: return None

        mid = beg + (end-beg)/2

        lhs = self.ll2tfaster_dfs2(beg, mid-1)
        tn = BTNode(self.node.val)
        tn.left = lhs
        self.node = self.node.next
        rhs = self.ll2tfaster_dfs2(mid+1, end)
        tn.right = rhs
        return tn
開發者ID:victorfei,項目名稱:interview,代碼行數:12,代碼來源:linkedlistToBST.py

示例12: ll2tfaster_dfs

 def ll2tfaster_dfs(self, n):
     # n/2: left side length n/2
     # n-n/2-1: right_side_len: total_len - lft_len - mid
     # note: lhs = n/2-1, rhs = n-n/2 does not work
     # e.g. [1, 2, 3]
     if n == 0: return None
     lhs = self.ll2tfaster_dfs(n/2)
     tn = BTNode(self.node.val)
     self.node = self.node.next
     rhs = self.ll2tfaster_dfs(n -n/2-1)
     tn.left = lhs
     tn.right = rhs
     return tn
開發者ID:victorfei,項目名稱:interview,代碼行數:13,代碼來源:linkedlistToBST.py

示例13: test1

def test1():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n5 = BTNode(5)
    n7 = BTNode(7)
    n9 = BTNode(9)
    n8 = BTNode(8)

    n1.left = n2
    n2.left = n5
    n2.right = n9
    n5.left = n7
    n9.left = n8

    print(rightView(n1))
開發者ID:victorfei,項目名稱:interview,代碼行數:15,代碼來源:rightView.py

示例14: test3

def test3():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n3 = BTNode(3)
    n4 = BTNode(4)
    n5 = BTNode(5)
    n7 = BTNode(7)

    n1.left = n2
    n2.left = n3
    n3.left = n4
    n4.left = n5
    n5.left = n7

    rslt = []
    inOrderTrav(n1, rslt)
    print(rslt)
    print(inOrderTravRec(n1))
    print("--------------")
開發者ID:victorfei,項目名稱:interview,代碼行數:19,代碼來源:inOrderTrav.py

示例15: test2

def test2():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n3 = BTNode(3)
    n4 = BTNode(4)
    n5 = BTNode(5)
    n6 = BTNode(6)
    n7 = BTNode(7)

    n1.left = n2
    n1.right = n3
    n2.left = n4
    n2.right = n5
    n3.left = n6
    n3.right = n7

    print(sumRoot2LeafNumbers(n1))
開發者ID:victorfei,項目名稱:interview,代碼行數:17,代碼來源:sumRoot2LeafNumbers.py


注:本文中的btNode.BTNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。