首页 > 编程语言 > 详细

Leetcode 226 Invert Binary Tree python

时间:2016-04-16 00:42:35      阅读:357      评论:0      收藏:0      [点我收藏+]

题目:

Invert a binary tree. 翻转二叉树。

 

递归,每次对节点的左右节点调用invertTree函数,直到叶节点。

python中也没有swap函数,当然你可以写一个,不过python中可以通过:a, b = b, a交换两个变量的值

 

1 class Solution(object):
2     def invertTree(self, root):
3         if root == None: return root
4         root.left, root.right = self.invertTree(root.right), self.invertTree(root.left)
5         return root

 

Leetcode 226 Invert Binary Tree python

原文:http://www.cnblogs.com/def-ly/p/5397288.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!