[leetcode]:Invert a binary tree.
2017-05-16 13:29
417 查看
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; }
相关文章推荐
- LEETCODE-Invert Binary Tree
- [LeetCode]226. Invert Binary Tree
- 【LeetCode】Invert Binary Tree 翻转二叉树 - Easy++
- 《leetCode》:Invert Binary Tree
- LeetCode | Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode[226] Invert Binary Tree
- LeetCode_ Invert Binary Tree
- LeetCode-226. Invert Binary Tree
- leetcode 226. Invert Binary Tree
- [leetcode-226]Invert Binary Tree(c++)
- [LeetCode-226]Invert Binary Tree(java)
- LeetCode226——Invert Binary Tree
- leetcode Invert Binary Tree python
- LeetCode------Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode:Invert Binary Tree
- Leetcode 226. Invert Binary Tree (Easy) (cpp)
- LeetCode-226 Invert Binary Tree
- LeetCode--Invert Binary Tree