[leetcode]:Invert a binary tree.
来源:互联网 发布:好看的字体软件 编辑:程序博客网 时间:2024/05/21 15:02
1.题目
翻转一棵二叉树
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
2.分析
遍历树,交换左右节点。可以手动遍历或递归
3.代码
TreeNode* invertTree(TreeNode* root) { if (root == NULL) return root; TreeNode* tempL= invertTree(root->right); TreeNode* tempR = invertTree(root->left); root->left = tempL; root->right = tempR; return root;}
阅读全文
0 0
- [leetcode]:Invert a binary tree.
- [LeetCode] 226 Invert a binary tree.
- <LeetCode><Easy>226Invert a binary tree
- Leetcode 226:Invert a 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
- Java中的类加载器
- 完成顶部标题栏和ViewPager的功能
- 关于JSON和JSONP
- 数字金字塔
- Cypher语言
- [leetcode]:Invert a binary tree.
- 软链接与硬链接
- POI操作EXCEL,追加或覆盖数据,输入输出流注意事项,jar包的选择
- C++基础知识
- 淘宝中的一些基本CSS代码
- 函数重载
- Java通过Socket实现UDP编程及Socket总结
- swift面向协议编程
- Window 窗口层次关系