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 was inspired by this original tweet by Max Howell:
解题思路:
递归即可,JAVA实现如下:
public TreeNode invertTree(TreeNode root) {
if(root==null)
return root;
TreeNode temp=root.left;
root.left=root.right;
root.right=temp;
invertTree(root.left);
invertTree(root.right);
return root;
}
Java for LeetCode 226 Invert Binary Tree的更多相关文章
- 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 (反转二叉树)
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 class Solution(object): ...
- (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 ...
- Leetcode 226 Invert Binary Tree python
题目: Invert a binary tree. 翻转二叉树. 递归,每次对节点的左右节点调用invertTree函数,直到叶节点. python中也没有swap函数,当然你可以写一个,不过pyth ...
- 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(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. 题目分析及思路 给定一棵二叉树,要求每一层的结点逆序.可以使用递归的思想将左右子树互换. 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 Trivia:This problem was ...
随机推荐
- 如何解压.bz2文件包
.bz2 解压1:bzip2 -d FileName.bz2 解压2:bunzip2 FileName.bz2 压缩: bzip2 -z FileName .tar.bz2 解压:tar j ...
- Maven初级学习(二)Maven使用入门
序,学习配置pom.xml,利用maven生成eclipes项目. 一.编写POM POM Project Obejct Model,项目对象模型. 编写pom.xml,新建文件夹hello-worl ...
- 一行代码解决各种IE兼容问题IE8,IE9,IE10
一:一.指定文件兼容性模式(Xee:因为我已经放弃IE6,7了,所以以后设计的网页最低支持IE8;) 要为你的网页指定文件模式,需要在你的网页中使用meta元素放入X-UA-Compatible ht ...
- python的re正则表达式模块学习
python中re模块的用法 Python 的 re 模块(Regular Expression 正则表达式)提供各种正则表达式的匹配操作,在文本解析.复杂字符串分析和信息提取时是一个非常有用的工 ...
- Mac Pro 安装 Sublime Text 2.0.2,个性化设置,主题 和 插件 收藏
1.到官网下载安装包 http://www.sublimetext.com/2 2.附注册码一枚 ----- BEGIN LICENSE ----- Andrew Weber Single User ...
- Lab1--关于安装JUnit的简要描述
安装JUnit的过程描述: 下载两个jar包: hamcrest-all-1.3.jar junit-4.12.jar 注意在导入完成jar包之后不要随意改变jar包的路径. 创建java程序,书写如 ...
- C#之正则表达式、异常处理和委托与事件
正则表达式主要是为了处理和模式匹配复杂的字符串. int myInteger = 5; string intergerString = myInteger.ToString(); 就是将myInteg ...
- Spotlight on oracle
Spotlight on Oracle 能让你迅速发现任何性能瓶颈,无论是实时还是历史查询.Spotlight 能鉴别和诊断几千种性能问题,无论是特定用户问题.集中资源SQL事务. I/O瓶颈.锁定等 ...
- Javascript高级程序设计——函数
函数Function 通过函数封装多条语句,在任何地方执行.javascript函数不会重载,相同名字函数,名字属于后定义的函数通过function关键词声明. function functionNa ...
- java自定义标签 权限
<?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="http://java ...