226. Invert Binary Tree
来源:互联网 发布:淘宝网app怎么登录 编辑:程序博客网 时间:2024/06/04 19:42
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9to
4 / \ 7 2 / \ / \9 6 3 1递归遍历交换节点即可
/** * 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 root; TreeNode* temp; temp = root->left; root->left = root->right; root->right = temp; 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
- jquery插件效果
- BigDecimal数据类型(初始化,加减乘除,基本操作)
- 谈谈数据库的ACID
- 模仿NGUI实现SoftClip(二)
- MATLAB入门
- 226. Invert Binary Tree
- ACM 吝啬的国度
- HBase实战
- 支付网关的设计
- PyTorch contiguous 的概念
- Java并发工具类CountDownLatch
- maven 打包 jar包运行出错
- 中福光彩工程管理集团主创的初心
- CentOS下安装配置vsftp服务