本文整理汇总了Python中solution.Solution.inorderTraversal方法的典型用法代码示例。如果您正苦于以下问题:Python Solution.inorderTraversal方法的具体用法?Python Solution.inorderTraversal怎么用?Python Solution.inorderTraversal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solution.Solution
的用法示例。
在下文中一共展示了Solution.inorderTraversal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_1
# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import inorderTraversal [as 别名]
def test_1():
sol = Solution()
r = TreeNode(0)
a1 = TreeNode(1)
a2 = TreeNode(2)
a3 = TreeNode(3)
a4 = TreeNode(4)
a5 = TreeNode(5)
a6 = TreeNode(6)
r.left, r.right = a1, a2
a2.left, a2.right = a3, a6
a3.left, a3.right = a4, a5
assert sol.inorderTraversal(r) == [1, 0, 4, 3, 5, 2, 6]
示例2: TreeNode
# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import inorderTraversal [as 别名]
return TreeNode(int(s))
def createTree(tree):
q = []
root = constructOne(tree[0]);
q.append(root);
idx = 1;
while q:
tn = q.pop(0)
if not tn:
continue
if idx == len(tree):
break
left = constructOne(tree[idx])
tn.left = left
q.append(left)
idx += 1
if idx == len(tree):
break
right = constructOne(tree[idx])
idx += 1
tn.right = right
q.append(right)
return root
# inpt = createTree(['1', '#', '2', '3'])
inpt = createTree(['1', '2', '3', '#' , '#', '4', '#', '#', '5'])
sol = Solution()
res = sol.inorderTraversal(inpt)
print(res)
示例3: test_0
# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import inorderTraversal [as 别名]
def test_0():
sol = Solution()
assert sol.inorderTraversal(None) == []
r = TreeNode(0)
assert sol.inorderTraversal(r) == [0]