226. Invert Binary Tree
2015-12-20 23:28
204 查看
Invert a binary tree.
to
Trivia:
This problem was inspired by this
original tweet by Max
Howell:
Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
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:
Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
/** * 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: TreeNode* invertTree(TreeNode* root) { if(!root) return NULL; if(!root->left&&!root->right) return root; TreeNode* y=root->right; root->right=invertTree(root->left); root->left=invertTree(y); return root; } };
相关文章推荐
- C语言局部变量和全局变量
- maven 版本管理
- git reset soft,hard,mixed之区别深解
- test
- 格式化字符串漏洞简介
- phpmail
- SHU1954 Dispsy loves flowers
- PAT乙级题目1002构思的改进和实践
- 从头认识java-13.10 边界的作用
- 分享几种常见WEB服务器配置方案
- MVC 架构设计
- 【ahk】为招商证券通达信版增加热键显隐跳空缺口,热键ctrl+
- Linux无线网络设置(wpa_supplicant的使用)
- 40个Java多线程问题总结
- Bash远程文件传输命令scp
- 递归(c++)(转)
- .net MVC BundleConfig.cs 合并js和css文件说明文档
- 模式实现库函数strcpy,注意函数参数,返回值设计。参数检测
- 第十三章mvc模式与php框架
- 追MM与Java的23种设计模式