def main():
    a = [3, 9, 20, None, None, 15, 7]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().levelOrder(r)
    print(ret)
    print("---------------")

    a = [5, 4, 1, None, 1, None, 4, 2, None, 2, None]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().levelOrder(r)
    print(ret)
    print("---------------")
Ejemplo n.º 2
0
def main():
    a = [8, 3, 10, 1, 6, None, 14, None, None, 4, 7, 13]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().maxAncestorDiff(r)
    print(ret)
    print("---------------")

    a = [8]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().maxAncestorDiff(r)
    print(ret)
    print("---------------")
Ejemplo n.º 3
0
def main():
    p = [1, 2, 3]
    q = [1, 2, 3]
    p_t = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(p)
    q_t = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(q)
    ret = Solution().isSameTree(p_t, q_t)
    print(ret)
    print("---------------")

    p = [1, 2]
    q = [1, None, 2]
    p_t = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(p)
    q_t = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(q)
    ret = Solution().isSameTree(p_t, q_t)
    print(ret)
    print("---------------")

    p = [1, 2, 1]
    q = [1, 1, 2]
    p_t = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(p)
    q_t = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(q)
    ret = Solution().isSameTree(p_t, q_t)
    print(ret)
    print("---------------")

    p = [10, 5, 15]
    q = [10, 5, None, None, 15]
    p_t = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(p)
    q_t = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(q)
    ret = Solution().isSameTree(p_t, q_t)
    print(ret)
    print("---------------")
def main():
    a = [3, 9, 20, None, None, 15, 7]
    util = array_2_tree.ArrayToTreeUtil()
    s = util.trans_array_to_treenode_2(a)
    ret = Solution().minDepth(s)
    print(ret)
    print("--------------------")
Ejemplo n.º 5
0
def main():
    a = [3, 9, 20, None, None, 15, 7]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().verticalTraversal(r)
    print(ret)
    print("---------------")

    a = [1, 2, 3, 4, 5, 6, 7]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().verticalTraversal(r)
    print(ret)
    print("---------------")

    a = [0, None, 1, 2, 3, None, None, 4, 5]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().verticalTraversal(r)
    print(ret)
    print("---------------")

    a = [0, 1, None, None, 2, 6, 3, None, None, None, 4, None, 5]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().verticalTraversal(r)
    print(ret)
    print("---------------")

    a = [
        0, 5, 1, 9, None, 2, None, None, None, None, 3, 4, 8, 6, None, None,
        None, 7
    ]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().verticalTraversal(r)
    print(ret)
    print("---------------")

    a = [0, 8, 1, None, None, 3, 2, None, 4, 5, None, None, 7, 6]
    r = array_to_tree.ArrayToTreeUtil().trans_array_to_treenode_2(a)
    ret = Solution().verticalTraversal(r)
    print(ret)
    print("---------------")
Ejemplo n.º 6
0
def main():
    s_array = [3, 4, 5, 1, 2]
    t_array = [4, 1, 2]
    util = ArrayToTreeUtil.ArrayToTreeUtil()
    s = util.trans_array_to_treenode_2(s_array)
    t = util.trans_array_to_treenode_2(t_array)
    ret = Solution().isSubtree(s, t)
    print(ret)
    print("--------------------")

    s_array = [3, 4, 5, 1, 2, None, None, 0]
    t_array = [4, 1, 2]
    util = ArrayToTreeUtil.ArrayToTreeUtil()
    s = util.trans_array_to_treenode_2(s_array)
    t = util.trans_array_to_treenode_2(t_array)
    ret = Solution().isSubtree(s, t)
    print(ret)
    print("--------------------")

    s_array = [
        4, -9, 5, None, -1, None, 8, -6, 0, 7, None, None, -2, None, None,
        None, None, -3
    ]
    t_array = [5]
    util = ArrayToTreeUtil.ArrayToTreeUtil()
    s = util.trans_array_to_treenode_2(s_array)
    t = util.trans_array_to_treenode_2(t_array)
    ret = Solution().isSubtree(s, t)
    print(ret)
    print("--------------------")

    s_array = [4]
    t_array = [4]
    util = ArrayToTreeUtil.ArrayToTreeUtil()
    s = util.trans_array_to_treenode_2(s_array)
    t = util.trans_array_to_treenode_2(t_array)
    ret = Solution().isSubtree(s, t)
    print(ret)
    print("--------------------")

    s_array = [14]
    t_array = [4]
    util = ArrayToTreeUtil.ArrayToTreeUtil()
    s = util.trans_array_to_treenode_2(s_array)
    t = util.trans_array_to_treenode_2(t_array)
    ret = Solution().isSubtree(s, t)
    print(ret)
    print("--------------------")

    s_array = [1, 1]
    t_array = [1]
    util = ArrayToTreeUtil.ArrayToTreeUtil()
    s = util.trans_array_to_treenode_2(s_array)
    t = util.trans_array_to_treenode_2(t_array)
    ret = Solution().isSubtree(s, t)
    print(ret)
    print("--------------------")

    s_array = [3, 4, 5, 1, None, 2]
    t_array = [3, 1, 2]
    util = ArrayToTreeUtil.ArrayToTreeUtil()
    s = util.trans_array_to_treenode_2(s_array)
    t = util.trans_array_to_treenode_2(t_array)
    ret = Solution().isSubtree(s, t)
    print(ret)
    print("--------------------")