码迷,mamicode.com
首页 > 其他好文 > 详细

剑指Offer 27

时间:2019-06-12 23:18:28      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:ror   pre   roo   tree   ret   HERE   solution   bsp   temp   

 1 # -*- coding:utf-8 -*-
 2 # class TreeNode:
 3 #     def __init__(self, x):
 4 #         self.val = x
 5 #         self.left = None
 6 #         self.right = None
 7 class Solution:
 8     # 返回镜像树的根节点
 9     def Mirror(self, root):
10         if root == None:
11             return None
12         if root.left != None and root.right != None:
13             temp = TreeNode(root.val)
14             temp.left = root.left
15             root.left = self.Mirror(root.right)
16             root.right = self.Mirror(temp.left)
17         elif root.left == None and root.right != None:
18             root.left = self.Mirror(root.right)
19             root.right = None
20         elif root.right == None and root.left != None:
21             root.right = self.Mirror(root.left)
22             root.left = None
23         return root
24         # write code here

 

剑指Offer 27

标签:ror   pre   roo   tree   ret   HERE   solution   bsp   temp   

原文地址:https://www.cnblogs.com/asenyang/p/11013140.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!