226. Invert Binary Tree
来源:互联网 发布:win10系统改mac地址 编辑:程序博客网 时间:2024/06/05 18:33
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.
Subscribe to see which companies asked this question
代码
/** * 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==NULL) return NULL; swap(root->left,root->right); invertTree(root->left); invertTree(root->right); return root; }};
0 0
- 226.Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 省市县三级联动(与后台仅交互一次)
- 周六还上班,git走起
- Codeforces Round #360 (Div. 2) -- C. NP-Hard Problem (DFS二分图染色法)
- Install vim after installing ubuntu
- 基于OpenLayers实战地理信息系统视频
- 226. Invert Binary Tree
- linux 下 I2C 设备驱动 实现 总结 s3c2440
- 八种有效手段确保云计算服务安全通过加密等方法实现云数据安全
- Supervisor学习心得
- 高仿ios钉钉菜单展示效果
- 判断手机有无外置sd卡
- 读《摄影师的故事》
- 定风波·南海归赠王定国侍人寓娘
- 解决MySQL : InnoDB: Cannot allocate memory for the buffer pool