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


Python TreeNode.makeTree方法代码示例

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


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

示例1: test_rightSideView

# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import makeTree [as 别名]
 def test_rightSideView(self):
     s = LeetSolution()
     self.assertEqual([], s.rightSideView(None))
     root = TreeNode.makeTree([1, 2, 3, '#', 5, '#', 4])
     self.assertEqual([1, 3, 4], s.rightSideView(root))
     root = TreeNode.makeTree([1, 2, 3, '#', 5, '#', 4, 6])
     self.assertEqual([1, 3, 4, 6], s.rightSideView(root))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:9,代码来源:test_leetSolution.py

示例2: test_inorder

# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import makeTree [as 别名]
 def test_inorder(self):
     root = TreeNode.makeTree([1, '#', 2, 3])
     self.assertEqual([1, 3, 2], BTTraversal.inorder(root))
     root = TreeNode.makeTree([1, 2, 3, 4, 5, '#', 6])
     self.assertEqual([4, 2, 5, 1, 3, 6], BTTraversal.inorder(root))
     root = TreeNode.makeTree([3, 1, 4, '#', 2, '#', 5, '#', '#', '#', 6])
     self.assertEqual([1, 2, 3, 4, 5, 6], BTTraversal.inorder(root))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:9,代码来源:test_bttraversal.py

示例3: test_preorder

# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import makeTree [as 别名]
 def test_preorder(self):
     self.assertEqual([], BTTraversal.preorder([]))
     root = TreeNode.makeTree([1, '#', 2, 3])
     self.assertEqual([1, 2, 3], BTTraversal.preorder(root))
     root = TreeNode.makeTree([1, 2, 2, '#', 3, '#', 3])
     self.assertEqual([1, 2, 3, 2, 3], BTTraversal.preorder(root))
     root = TreeNode.makeTree([3, 1, 2])
     self.assertEqual([3, 1, 2], BTTraversal.preorder(root))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:10,代码来源:test_bttraversal.py

示例4: test_BSTIterator

# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import makeTree [as 别名]
 def test_BSTIterator(self):
     s = LeetSolution()
     root = TreeNode.makeTree([3, 1, 4, '#', 2, '#', 5, '#', '#', '#', 6])
     i, r = s.BSTIterator(root), []
     while i.hasNext():
         r.append(i.next())
     self.assertEqual([1, 2, 3, 4, 5, 6], r)
开发者ID:pengmeng,项目名称:LeetCode,代码行数:9,代码来源:test_leetSolution.py

示例5: test_isSameTree

# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import makeTree [as 别名]
 def test_isSameTree(self):
     self.assertTrue(
         LeetSolution().isSameTree(
             TreeNode.makeTree([1, 2, 2, 3, 4, 4, 3]), TreeNode.makeTree([1, 2, 2, 3, 4, 4, 3])))
     self.assertFalse(
         LeetSolution().isSameTree(
             TreeNode.makeTree([1, 2, 2, '#', 3, '#', 3]), TreeNode.makeTree([1, 2, 2, 3, '#', 3])))
     self.assertFalse(
         LeetSolution().isSameTree(
             TreeNode.makeTree([1, 2, '#', 3]), TreeNode.makeTree([1, '#', 2, '#', '#', '#', 3])))
     self.assertTrue(LeetSolution().isSameTree(None, None))
     self.assertFalse(LeetSolution().isSameTree(TreeNode.makeTree([1]), None))
     self.assertTrue(LeetSolution().isSameTree(TreeNode.makeTree([1]), TreeNode.makeTree([1])))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:15,代码来源:test_leetSolution.py

示例6: test_issym

# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import makeTree [as 别名]
 def test_issym(self):
     self.assertTrue(LeetSolution().isSymmetric(None))
     self.assertTrue(LeetSolution().isSymmetric(TreeNode.makeTree([1, 2, 2, 3, 4, 4, 3])))
     self.assertFalse(LeetSolution().isSymmetric(TreeNode.makeTree([1, 2, 2, '#', 3, '#', 3])))
     self.assertFalse(LeetSolution().isSymmetric(TreeNode.makeTree([1, '#', 2, '#', '#', '#', 3])))
     self.assertTrue(LeetSolution().isSymmetric(TreeNode.makeTree([1])))
     self.assertFalse(LeetSolution().isSymmetric(TreeNode.makeTree([1, 2, 3])))
     self.assertFalse(LeetSolution().isSymmetric(TreeNode.makeTree([2, 3, 3, 4, 5, 5])))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:10,代码来源:test_leetSolution.py

示例7: test_zigzagLevelOrder

# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import makeTree [as 别名]
 def test_zigzagLevelOrder(self):
     s = LeetSolution()
     self.assertEqual([[3], [20, 9], [15, 7]], s.zigzagLevelOrder(TreeNode.makeTree([3, 9, 20, '#', '#', 15, 7])))
     self.assertEqual([[1], [3, 2], [4, 5]], s.zigzagLevelOrder(TreeNode.makeTree([1, 2, 3, 4, '#', '#', 5])))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:6,代码来源:test_leetSolution.py

示例8: test_levelOrder

# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import makeTree [as 别名]
 def test_levelOrder(self):
     s = LeetSolution()
     self.assertEqual([[3], [9, 20], [15, 7]], s.levelOrder(TreeNode.makeTree([3, 9, 20, '#', '#', 15, 7])))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:5,代码来源:test_leetSolution.py


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