本文整理汇总了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))
示例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))
示例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))
示例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)
示例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])))
示例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])))
示例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])))
示例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])))