LeetCode: Invert Binary Tree
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public TreeNode invertTree(TreeNode root) {
if (root == null) return null;
TreeNode tmp = root.left;
root.left = invertTree(root.right);
root.right = invertTree(tmp);
return root;
}
}
LeetCode: Invert Binary Tree的更多相关文章
- LeetCode—— Invert Binary Tree
LeetCode-- Invert Binary Tree Question invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 ...
- [LeetCode] 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 ...
- LeetCode——Invert Binary Tree
Description: Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9 to 4 / \ 7 2 / \ ...
- LeetCode Invert Binary Tree 反转二叉树
思路:递归解决,在返回root前保证该点的两个孩子已经互换了.注意可能给一个Null. C++ /** * Definition for a binary tree node. * struct Tr ...
- leetcode Invert Binary Tree python
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...
- LeetCode —— Invert Binary Tree
struct TreeNode* invertTree(struct TreeNode* root) { if ( NULL == root ) { return NULL; } if ( NULL ...
- lc面试准备:Invert Binary Tree
1 题目 Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 接口: public TreeNod ...
- <LeetCode OJ> 226. Invert Binary Tree
226. Invert Binary Tree Total Accepted: 57653 Total Submissions: 136144 Difficulty: Easy Invert a bi ...
- Python解Leetcode: 226. Invert Binary Tree
leetcode 226. Invert Binary Tree 倒置二叉树 思路:分别倒置左边和右边的结点,然后把根结点的左右指针分别指向右左倒置后返回的根结点. # Definition for ...
随机推荐
- 解决 卸载Mysql后,服务还在的问题
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\Application\MySQL文件夹:删除HKEY_LOCAL_MACHINE\ ...
- 【BZOJ】3714: [PA2014]Kuglarz
题意 \(n(1 \le n \le 2000)\)个数每个数是\(0\)或\(1\),现在可以花费\(c_{i, j}\)知道\([i, j]\)的奇偶性,问将所有数都找出来的最小花费. 分析 如果 ...
- Servlet生命周期
初始化:正常情况下,一个Servlet程序在第一次运行时才进行初始化. 刷新只会刷新服务,并没有初始化 销毁:1,容器关闭 2,一个servlet长期不适用 3,开发过程中的reload操作 对 ...
- [LintCode] Single Number 单独的数字
Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Have you met this question in ...
- hdu 5122
只要一个数的后面有比它小的数,这个数就要移,于是从后往前一趟遍历,记录一下这些数的个数就可以了. #include"iostream" #include"stdio.h& ...
- java核心技术第一卷
sell窗口(dos窗口命令)中要注意大小写: 编译java文件需要加上扩展名,运行java.class时只要文件名java,不需要扩展名:
- 20145205《Java程序设计》课程总结
每周读书笔记链接汇总 20145205 <Java程序设计>第1周学习总结 20145205<Java程序设计>第2周学习总结 20145205 <Java程序设计> ...
- x86架构手机跑安卓好吗?(脑补)
华硕低价位手机ZenFone一推出就掀起市场话题,许多人也对ZenFone所采用的Intel Atom处理器有所意见,深怕其相容性问题无法正确执行应用程式App,这究竟是怎么回事呢? Intel近几年 ...
- Apache2 worker
http://www.php-internals.com/book/?p=chapt08/08-03-zend-thread-safe-in-php 在多线程系统中,进程保留着资源所有权的属性,而多个 ...
- 贪吃蛇的java代码分析(二)
代码剖析 贪吃蛇是一款十分经典的小游戏,对初入coding的朋友来说,拿贪吃蛇这样一个案例来练手十分合适,并不高的难度和成功后的成就感都是学习所必须的.下面我将依照我当时的思路,来逐步分析实现的整个过 ...