当前位置: 首页>>代码示例>>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;未经允许,请勿转载。