Leetcode 226 Invert Binary Tree python
题目:
Invert a binary tree. 翻转二叉树。
递归,每次对节点的左右节点调用invertTree函数,直到叶节点。
python中也没有swap函数,当然你可以写一个,不过python中可以通过:a, b = b, a交换两个变量的值
class Solution(object):
def invertTree(self, root):
if root == None: return root
root.left, root.right = self.invertTree(root.right), self.invertTree(root.left)
return root
Leetcode 226 Invert Binary Tree python的更多相关文章
- LeetCode 226. Invert Binary Tree (反转二叉树)
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
- leetcode 226 Invert Binary Tree 翻转二叉树
大牛没有能做出来的题,我们要好好做一做 Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Tri ...
- LeetCode 226 Invert Binary Tree 解题报告
题目要求 Invert a binary tree. 题目分析及思路 给定一棵二叉树,要求每一层的结点逆序.可以使用递归的思想将左右子树互换. python代码 # Definition for a ...
- Leetcode 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 class Solution(object): ...
- Java for LeetCode 226 Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem wa ...
- (easy)LeetCode 226.Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
- Java [Leetcode 226]Invert Binary Tree
题目描述: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 解题思路: 我只想说递归大法好. ...
- Leetcode 226. Invert Binary Tree(easy)
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
- LeetCode (226):Invert Binary Tree 递归实现
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
随机推荐
- 清除浮动 .clearfix
子元素的浮动 清除子元素的浮动 .clearfix{zoom:1}/*IE 6-8*/.clearfix:after{content:'\20';display:block;height:0;clea ...
- php在cli和cgi方式下获取服务器ip的实例
php cli方式下获取服务器ip php内核没有提供这样的命令,需要借助linux中的命令ifconfig来实现,如下两个函数代码: function getServerIp(){ ...
- sqlsever连接两个不同服务器上的数据库进行查询
exec sp_addlinkedserver 'LocalSERVER' ,--别名,自己起一个 '' , 'SQLOLEDB' , 'ip' --远程服务器地址 exec sp_addlinked ...
- Struts2+JQuery+JSON实现异步交互
1.环境 jquery:jquery-1.9.0.min.js struts2:基本包就不说了,就说说应用json的包,主要有struts2-json-plugin-2.3.8.jar json:js ...
- 在WPF中使用ArcGIS Engine
原文 http://blog.csdn.net/zzahkj/article/details/9102621 1.首先,新建一个WPF项目,添加引用ESRI.ArcGIS.AxControls.ESR ...
- perl return和break
zjzc01:/root/test# cat a3.pl sub mask { my $n=shift; my $j =100; for ($i = 1;$i <= 5;$i++){ print ...
- 自制简单表单验证relative与absolute定位
html结构,用到了label与span <label class="relative"><input type="text" name=&q ...
- WebStorm JavaScript 开发神器
WebStorm 百度百科 http://baike.baidu.com/view/5443872.htm?fr=aladdin
- oracle数据库时间转换
select * from TAB where 时间 BETWEEN to_date('2011-02-01 22:03:40','yyyy-mm-dd hh24:mi:ss') and to_dat ...
- Elasticsearch 安装与集群配置
一.软件版本 操作系统:CentOS-6.5-x86_64 ES版本:5.0 主机:192.168.63.246 主机: 192.168.63.242 二.部署环境规划: 1. 需求:jdk版本: ...