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 ...
随机推荐
- 【Oracle】oracle之listagg分析函数
oracle分析函数——listagg篇 (1)使用listagg将多行数据合并到一行 例表: select deptno, ename from emp order by deptno, ename ...
- HTML5新增的标签
结构性元素<header><footer>定义页眉(与<head>不一样)和页脚 <section>定义section<article> 定 ...
- MSSQL跨服务器插入
跨服器插入数据 其中服务器的IP为源数据地址 还要注意的是目标库中不能存在对应表. select * INTO compMaintype from openrowset('SQLOLEDB' , ' ...
- Javascript初学篇章_3(注释/if/switch)
五.javascript的注释 // 单行注释 /* …*/ 多行注释 注:多行注释不能互相嵌套 六.程序流程控制 一.条件语句 if 语法: if(condition) statements1 el ...
- tomcat下jsp要加工程名后缀才能访问的问题解决
今天发现一个部署的项目,在tomcat中配置了去掉工程名,直接通过域名访问.配置后其它的html.动态请求等都可以不带工程名访问,但是只要访问jsp页面就报404错误,加上工程名访问jsp却又正常. ...
- 第八周PSP
团队项目PSP 一:表格 C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论用户界面 8:40 11:40 35 60 70 分析与 ...
- [转自itilxf论坛]iTop百问百答
iTop是什么,和其他itsm软件相比有什么优势?iTop,是一个开源web应用程序,用于IT环境的日常运营.它基于ITIL最佳实践,而又不拘泥于任何具体流程. 优势: 1. 开源,扩展性强容易开发. ...
- springboot+solr
整合完DB层,cache层,开始整合solr. 注入SolrClient, package hello.configuration; import java.net.MalformedURLExcep ...
- Autofac
程序集准备 Assembly: Autofac/Autofac.Integration.Mvc/System.Web.Mvc/System.Web.Helpers/System.Web.WebPage ...
- surface pro 4 wifi掉线问题
更新你的无线网卡驱动到最新版本15.68.9032.47,重启.或者运行regedit修改注册表 HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\mr ...