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 ...
随机推荐
- kafka-manager安装
代码地址: https://github.com/yahoo/kafka-manager 注意只能使用 Java 7!Java 6 编译不通过,Java 8 在运行的时候会报错:java.lang.U ...
- DLL技术应用04 - 零基础入门学习Delphi47
DLL技术应用04 让编程改变世界 Change the world by program 利用DLL实现窗体重用 利用 Delphi 的 DLL 功能,不但能够实现过程和函数重用,而且还可以实现窗体 ...
- Taglib、EL、OGNL
Taglib.EL.OGNL 阅读目录 1. Taglib(tag library) 标签库 2. EL(Expression Language) 表达式 3. OGNL(Object-Graph N ...
- 使用TypeScript实现简单的HTML5贪吃蛇游戏
TypeScript是一种由微软开发的自由和开源的编程语言.它是JavaScript的一个超集,而且本质上向这个语言添加了可选的静态类型和基于类的面向对象编程.安德斯·海尔斯伯格,C#的首席架构师,已 ...
- ExtJs Model之convert的使用
convert: function(value,record){} value:为当前属性的值,record.get('属性')用来获取其他属性的值. 以下案例是:将年龄减去2. Ext.define ...
- VIJOS 1889 天真的因数分解(莫比乌斯反演,容斥原理)
https://vijos.org/p/1889 同BZOJ2440..,不过这题要求的是有因数因子的,所以莫比乌斯函数要稍微改一下 #include<algorithm> #includ ...
- C# 将字节流转换为图片的实例方法
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Dr ...
- [每日一题] 11gOCP 1z0-052 :2013-09-25 Lock ――for update.................................C23
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/12021587 正确答案:ABE 这道题需要我们了解锁的知识点. TM锁的模式: 0-Non ...
- http的无状态无连接到底是什么含义
无连接:服务器处理完客户的请求,并收到客户的应答后,即断开连接. 早期这么做的原因是 HTTP协议产生于互联网,因此服务器需要处理同时面向全世界数十万.上百万客户端的网页访问,但每个客户端(即浏览器) ...
- Socket 相关的知识
1.关于PF_INET和AF_INET的区别 在写网络程序的时候,建立TCP socket: sock = socket(PF_INET, SOCK_STREAM, 0);然后在绑定本地地址或连接远程 ...