Invert Binary Tree(easy)
1.直接把递归把左右子树翻转即可
AC代码:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void invert(TreeNode* root)
{
if (root != NULL)
{
swap(root->left, root->right);
invert(root->left);
invert(root->right);
} }
TreeNode* invertTree(TreeNode* root) {
invert(root);
return root;
} };
Invert Binary Tree(easy)的更多相关文章
- 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
226. Invert Binary Tree Easy Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: ...
- 【07_226】Invert Binary Tree
Invert Binary Tree Total Accepted: 54994 Total Submissions: 130742 Difficulty: Easy Invert a binary ...
- 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 ...
- 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 ...
- 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 ...
- [LintCode] Invert Binary Tree 翻转二叉树
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
随机推荐
- FFmpeg的基本使用
1.FFmpeg理解 (1)FFmpeg是一个视屏.音频编码工具 (2)x项目名称mpeg来源mpeg编码标准,但不局限只能使用mpeg编码标准.FF 表示fast forward (3)被广泛使用. ...
- SpringCloud学习之手把手教你用IDEA搭建入门项目(三)
本篇博客是承接上一篇<手把手教你用IDEA搭建SpringCloud入门项目(二)>,不清楚的请到我的博客空间查看后再看本篇博客,上面两篇博客成功创建了一个简单的SpringCloud项目 ...
- Python快速安装库的靠谱办法
我们如果使用python,并且使用pip安装一些库 会经常遇到pip在线安装速度慢 ! 慢也就算了,安装经常会由于timeout等原因中断 所以有没有什么在线安装库并且速度较快的办法么? 其实是有 ...
- Vue.js(15)之 json-server搭建模拟的API服务器
json-server搭建模拟的API服务器 运行命令 npm install json-server -D 全局安装 json-server 项目根目录下创建 mock 文件夹 mock 文件夹下添 ...
- HTTPS(身披SSL协议的HTTP)
参考链接: HTTP 与 HTTPS 的区别 HTTPS科普扫盲帖 HTTPS小结 HTTP 和 HTTPS 区别 HTTP是明文传输未加密,安全性差,HTTPS(HTTP + SSL)数据传输是加密 ...
- addlayer添加神经网络层
def addlayer(inputs,insize,outsize,activity_function = None): weights = tf.Variable(tf.random_nor ...
- git子模块使用
如下项目有多个标红的子模块 1.首先进入每个子模块目录,init初始化子模块仓库,然后提交远程. 2.在每个子目录都初始化好仓库后,进入lv-qggz主目录,只初始化该仓库,然后依次添加子模块的仓库地 ...
- Eclipse换DarkestDark主题之后,无法使用快捷键
问题出现: 在选用Eclipse插件的MarketPlace的时候,发现一个下载量很高的主题,看起来很不错,毫不犹豫的就下下来了. 说时迟那时快,下下来之后果然好看,不过问题也来了,快捷键失效了,Ct ...
- go语言实现leetcode-242
package main import ( "fmt" "reflect" ) func isAnagram(s string, t string) bool ...
- Java正则表达式基础知识整理
指定为字符串的正则表达式必须首先被编译为此类的实例.然后,可将得到的模式用于创建 Matcher 对象,依照正则表达式,该对象可以与任意字符序列匹配.执行匹配所涉及的所有状态都驻留在匹配器中,所以多个 ...