[LC] 226. Invert Binary Tree
Invert a binary tree.
Example:
Input:
- 4
- / \
- 2 7
- / \ / \
- 1 3 6 9
Output:
- 4
- / \
- 7 2
- / \ / \
- 9 6 3 1
- /**
- * Definition for a binary tree node.
- * public class TreeNode {
- * int val;
- * TreeNode left;
- * TreeNode right;
- * TreeNode(int x) { val = x; }
- * }
- */
- class Solution {
- public TreeNode invertTree(TreeNode root) {
- if (root == null) {
- return null;
- }
- TreeNode left = invertTree(root.left);
- TreeNode right = invertTree(root.right);
- root.left = right;
- root.right = left;
- return root;
- }
- }
[LC] 226. Invert Binary Tree的更多相关文章
- 226. Invert Binary Tree(C++)
226. Invert Binary Tree Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 ...
- LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...
- C#版 - 226. Invert Binary Tree(剑指offer 面试题19) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - 2 ...
- <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 ...
- 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 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 ...
随机推荐
- 网页时不时打不开?试试阿里DNS 233.5.5.5 /233.6..6.6
最经上网都是用手机热点,但发现用谷歌浏览器时,时不时打不开网页.最后发现是DNS的问题,原来我的dns是8.8.8.8. 最后更改成阿里的DNS 233.5.5.5 /233.6..6.6,打开网页流 ...
- Xcode7以后访问http加密
Xcode7 在Info.plist中add Row添加NSAppTransportSecurity类型Dictionary. 在NSAppTransportSecurity下添加NSAllowsAr ...
- 201604-1 折点计数 Java
思路: 这个题要小心考虑不全.左右两边都比这个数小 或者 左右两边都比这个数大 import java.util.Scanner; public class Main { public static ...
- c语言中用简单方法对多维数组进行初始化
例:int array[4][3] = {1,2,3,4,5,6,7,8,9,10,11,12}; 说明:a.由4*3可知,本二维数组包含12个元素,因此初始化时array[0][0] = 1 ,ar ...
- 用c语言实现的几个小项目
1.参考:Linux系统编程 2.参考:制作简单计算器 3.参考:制作2048小游戏 4.参考:五子棋实现
- Evaluation metrics for classification
Accuracy/Error rate ACC = (TP+TN)/(P+N) ERR = (FP+FN)/(P+N) = 1-ACC Confusion matrix Precision/Recal ...
- drf三大认证:认证组件-权限组件-权限六表-自定义认证组件的使用
三大认证工作原理简介 认证.权限.频率 源码分析: from rest_framework.views import APIView 源码分析入口: 内部的三大认证方法封装: 三大组件的原理分析: 权 ...
- win10下安装cygwin全过程
简单讲:cygwin就是在windows系统上跑linux和unix的环境,跨平台移植的应用程序移植. 安装步骤: 下载cygwin: 打开官网https://cygwin.com/install.h ...
- Unicode的认识
Unicode(统一码.万国码.单一码),它是为解决传统的字符编码方案的局限而产生的,它为每种语言中的每个字符设定了统一并且唯一的二进制码,以满足跨语言跨平台进行文本转换.处理的要求.1990年开始研 ...
- goweb-安装go及配置go
安装go及配置go 安装go 写这篇博客时,我的电脑的windows已经安装过了go,用的是标准包安装,不过我的linux操作系统还没安装,可以考虑用第三方工具安装,因为看了goweb这本书,我才知道 ...