请完成一个函数,输入一棵二叉树,该函数输出它的镜像。
class Solution:
def mirror_recursively(self, root):
if root:
root.left, root.right = root.right, root.left
self.mirror(root.left)
self.mirror(root.right)
return root
循环版
class Solution:
def mirror(self, root):
if not root:
return root
stack = [root]
while stack:
node = stack.pop()
node.left, node.right = node.right, node.left
if node.left:
stack.append(node.left)
if node.right:
stack.append(node.right)
return root
(最近更新:2019年07月24日)
2908


&spm=1001.2101.3001.11974&articleId=100049967&d=1&t=3&u=3763c3e6d3a749ed8b8a1c31c027b97a)

被折叠的 条评论
为什么被折叠?



