Invert Binary Tree
2016-07-22 23:46
295 查看
https://leetcode.com/problems/invert-binary-tree/
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
给出一棵二叉树,求这棵二叉树的镜像。
搬运九章上的实现 http://www.jiuzhang.com/solutions/invert-binary-tree/?source=zhmhw
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
给出一棵二叉树,求这棵二叉树的镜像。
搬运九章上的实现 http://www.jiuzhang.com/solutions/invert-binary-tree/?source=zhmhw
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* invertTree(struct TreeNode* root) { if(root == 0) return NULL; struct TreeNode *left = root->left; struct TreeNode *right = root->right; root->left = right; root->right = left; if(root->left != NULL) invertTree(root->left); if(root->right != NULL) invertTree(root->right); return root; }
相关文章推荐
- Android 手势的识别
- javaee之session的购物车练习
- HDU:1061 Rightmost Digit(规律)
- (三):HDU-Doing Homework again
- js中的面向对象程序设计(1)-对象和属性的类型
- 211. Add and Search Word - Data structure design
- 一个操作系统的实现中关于64位和32位的问题
- hdu 3440 House Man(差分约束)
- 合并两个排序的链表 C++
- 【杭电 1789 】Doing Homework again
- tomcat启动startup.bat一闪而过
- 内核打印杂谈
- 20 个 CSS 高级技巧汇总
- hdu 5744(想法题)
- javaee之cookie和session的见解和练习
- 15个你不可不知的cmd命令
- Codeforces 698A: Vacations(贪心)
- 为什么要内存对齐
- Morphia 学习一 注解
- 剑指offer——和为s的连续正数序列