LeetCode:Invert Binary Tree
来源:互联网 发布:听音乐的软件 编辑:程序博客网 时间:2024/06/01 08:52
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9to
4 / \ 7 2 / \ / \9 6 3 1Trivia:
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.
这道题有一个梗,homebrew的作者去Google面试就被问了这道题,结果他想了半天 没 想 出 来!哈哈哈
class Solution {public: TreeNode* invertTree(TreeNode* root) { if(root==NULL||root->left==NULL&&root->right==NULL){ return root; } TreeNode* temp=root->left; root->left=root->right; root->right=temp; if(root->left){ invertTree(root->left); } if(root->right){ invertTree(root->right); } return root; }};
0 0
- [leetcode] Invert Binary Tree
- [LeetCode]Invert Binary Tree
- leetcode:Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode | Invert Binary Tree
- leetcode--Invert Binary Tree
- [leetcode] Invert Binary Tree
- [LeetCode] Invert Binary Tree
- LeetCode Invert Binary Tree
- leetcode : Invert Binary Tree
- [LeetCode] Invert Binary Tree
- [Leetcode]Invert Binary Tree
- LeetCode: Invert Binary Tree
- LeetCode Invert Binary Tree
- leetcode: Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode || Invert Binary Tree
- LeetCode:Invert Binary Tree
- sparkR集群启动脚本的封装
- Struts2上传文件问题若干
- Filter
- Qt QAxObject操作excel文件过程总结
- HDU 5423:Rikka with Tree Dijkstra算法
- LeetCode:Invert Binary Tree
- iOS Working with Streams 处理流 官方文档翻译(四)
- C# ref 和 out ,params关键字的用法
- pat(B) 1006. 换个格式输出整数
- cocos2dx 3.7 创建工程
- shell脚本那点事儿3-5
- 为什么把成员函数声明为虚函数
- 欢迎使用CSDN-markdown编辑器
- 暑期小节