[Leetcode 226, Easy] Invert Binary Tree
2015-07-17 21:38
447 查看
Problem:
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.
Analysis:
Solutions:
C++:
Python:
Invert a binary tree.
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.
Analysis:
Solutions:
C++:
TreeNode* invertTree(TreeNode* root) { if (root == NULL) return root; TreeNode* p_left_subtree_root = invertTree(root->left); TreeNode* p_right_subtree_root = invertTree(root->right); root->left = p_right_subtree_root; root->right = p_left_subtree_root; return root; }Java:
Python:
相关文章推荐
- 女神教你字符串——违和感(字符串)
- Linux设置tomcat开机启动
- windows7旗舰版激活密钥
- zoj 3677 Paint Erased
- HDU4452——模拟——Running Rabbits
- CSU 1111 D(Contest #3)
- InteliJ IDEA + Genymotion搭建Android开发环境(win 7)
- 大型网站的灵魂——性能
- 关于获取config.properties文件内容
- POJ 1853 Cat
- poj 3468 A Simple Problem with Integers
- edittext 下划线颜色更改
- [翻译]Introduction to Monoids and Semigroups with Spark
- AngularJS性能优化心得,自己踩过的抗,及一些别人的经验(转哦)
- UVA - 11991 Easy Problem from Rujia Liu?
- Boost智能指针——scoped_ptr
- 关于LBP特征等价模式的解释
- User mode Linux
- POJ 1742 Coins
- vim 基本使用