LeetCode-Invert Binary Tree
来源:互联网 发布:sd卡数据修复 编辑:程序博客网 时间:2024/06/06 08:28
- problem:
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9
to
4 / \ 7 2 / \ / \9 6 3 1
- analysis:
利用递归将root的左节点赋值为转换了右子树的右节点,将root的右节点赋值为转换了左子树的左节点,并返回root。
- anwser:
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public TreeNode invertTree(TreeNode root) { if(root ==null) return root; TreeNode temp = null; temp = root.left; root.left=invertTree(root.right); root.right=invertTree(temp); return root; }}
0 0
- [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
- leetcode: Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode || Invert Binary Tree
- LeetCode:Invert Binary Tree
- How to Support 3D Touch - Static Action on Xcode6
- Android基础入门教程——8.1.2 Android中的13种Drawable小结 Part 2
- Code Forces 581 C. Developing Skills(贪心)
- C++primer第五版笔记-第九章顺序容器
- DBus 进程间的通信
- LeetCode-Invert Binary Tree
- hdu 1423 Greatest Common Increasing Subsequence 最长公共上升子序列
- 什么是EMC?说出至少三种测试实验项目,如何解决
- leetcode 1 Two Sum
- [Django入门知识浅介]再写一个Django动态程序
- UVa 1709 Amalgamated Artichokes
- CodeForce 584D Dima and Lisa(哥德巴赫猜想)
- HDU 5437 Alisha’s Party 优先队列
- MySQL技术之旅-MySQL的前世今生