当前位置: 首页>>代码示例>>Python>>正文


Python TreeNode.generate_bt_from_list方法代码示例

本文整理汇总了Python中util.tree_node.TreeNode.generate_bt_from_list方法的典型用法代码示例。如果您正苦于以下问题:Python TreeNode.generate_bt_from_list方法的具体用法?Python TreeNode.generate_bt_from_list怎么用?Python TreeNode.generate_bt_from_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在util.tree_node.TreeNode的用法示例。


在下文中一共展示了TreeNode.generate_bt_from_list方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_case3

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case3(self):
     nums = [6,5,8,1,3,7,11,None,None,None,None,None,None,9]
     answer = [6,3,8,1,5,7,11,None,None,None,None,None,None,9]
     root = TreeNode.generate_bt_from_list(nums)
     self.sol.recoverTree(root)
     compare = TreeNode.compare_tree(root, TreeNode.generate_bt_from_list(answer))
     self.assertTrue(compare)
开发者ID:linglingithub,项目名称:testhello,代码行数:9,代码来源:recover_binary_search_tree.py

示例2: test_case1

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case1(self):
     nums = [3,1,2]
     answer = [2,1,3]
     root = TreeNode.generate_bt_from_list(nums)
     self.sol.recoverTree(root)
     compare = TreeNode.compare_tree(root, TreeNode.generate_bt_from_list(answer))
     self.assertTrue(compare)
开发者ID:linglingithub,项目名称:testhello,代码行数:9,代码来源:recover_binary_search_tree.py

示例3: test_case2

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case2(self):
     nums = [5, 3, 6, 2, 4, None, 7]
     target = 28
     root = TreeNode.generate_bt_from_list(nums)
     answer = False
     result = self.sol.findTarget(root, target)
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:9,代码来源:two_sumIV_input_is_BST.py

示例4: test_case2

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case2(self):
     nums = [1,2]
     root = TreeNode.generate_bt_from_list(nums)
     answer = [1,2]
     self.sol.flatten(root)
     result = TreeNode.get_tree_right_list(root)
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:9,代码来源:flatten_binary_tree_to_linked_list.py

示例5: test_case02

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case02(self):
     nums = [2,1]
     k = 1
     root = TreeNode.generate_bt_from_list(nums)
     answer = 1
     result = self.sol.kthSmallest(root, k)
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:9,代码来源:kth_smallest_element_in_a_bst.py

示例6: test_case1

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case1(self):
     nums = [1,None,2]
     k = 2
     root = TreeNode.generate_bt_from_list(nums)
     answer = 2
     result = self.sol.kthSmallest(root, k)
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:9,代码来源:kth_smallest_element_in_a_bst.py

示例7: test_case1

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case1(self):
     nums = [3,9,20,None,None,15,7]
     answer = [
       [3],
       [9,20],
       [15,7]
     ]
     result = self.sol.levelOrder(TreeNode.generate_bt_from_list(nums))
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:11,代码来源:binary_tree_level_order_traversal.py

示例8: test_case1

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case1(self):
     nums = [1,2,3,None, None, None, 4]
     answer = 3
     result = self.sol.maxDepth(TreeNode.generate_bt_from_list(nums))
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:7,代码来源:maximum_depth_of_binary_tree.py

示例9: test_case5

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case5(self): # siblings can be one robbed and the other not.
     nums = [1,2,3,5,4]
     root = TreeNode.generate_bt_from_list(nums)
     answer = 12
     result = self.sol.rob(root)
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:8,代码来源:HouseRobberIII.py

示例10: test_case4

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case4(self):  # not necessarily rob by level, see this case, can skip the level
     nums = [4,1,None,2,None,None,None,3]
     root = TreeNode.generate_bt_from_list(nums)
     answer = 7
     result = self.sol.rob(root)
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:8,代码来源:HouseRobberIII.py

示例11: test_case3

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case3(self):
     nums = [0,0]
     root = TreeNode.generate_bt_from_list(nums)
     answer = 0
     result = self.sol.rob(root)
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:8,代码来源:HouseRobberIII.py

示例12: test_case1

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case1(self):
     nums = [1,2,3,4,5]
     root = TreeNode.generate_bt_from_list(nums)
     answer = 3
     result = self.sol.diameterOfBinaryTree(root)
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:8,代码来源:diameter_of_binary_tree.py

示例13: test_case3

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case3(self): #=====> need to check that all the vals in subtree also smaller or greater than the ROOT val!!
     nums = [10,5,15,None,None,6,20]
     answer = False
     result = self.sol.isValidBST(TreeNode.generate_bt_from_list(nums))
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:7,代码来源:validate_binary_search_tree.py

示例14: test_case2

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case2(self):
     nums = [1,2,3,4, None, None, None, 8]
     answer = False
     result = self.sol.isBalanced(TreeNode.generate_bt_from_list(nums))
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:7,代码来源:balanced_binary_tree.py

示例15: test_case1

# 需要导入模块: from util.tree_node import TreeNode [as 别名]
# 或者: from util.tree_node.TreeNode import generate_bt_from_list [as 别名]
 def test_case1(self):
     nums = [1,None, 2,3]
     answer = [1,2,3]
     result = self.sol.preorderTraversal(TreeNode.generate_bt_from_list(nums))
     self.assertEqual(answer, result)
开发者ID:linglingithub,项目名称:testhello,代码行数:7,代码来源:binary_tree_preorder_traversal.py


注:本文中的util.tree_node.TreeNode.generate_bt_from_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。