LeetCode_ Invert Binary Tree
来源:互联网 发布:淘宝上好的纯银耳饰店 编辑:程序博客网 时间:2024/06/05 03:09
Total Accepted: 60170 Total Submissions: 140987 Difficulty: Easy
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9to
4 / \ 7 2 / \ / \9 6 3 1Trivia:
如题,将一个二叉树翻转:
public class Solution { public TreeNode invertTree(TreeNode root) { /*if(root!=null){ TreeNode temp=root.left; temp.val=root.left.val; root.left=root.right; root.left.val=root.right.val; root.right=temp; root.right.val=temp.val; } return root; */ if(root==null) return root; TreeNode temp; 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
- Invert Binary Tree
- leetcode:Invert Binary Tree
- Invert Binary Tree
- LeetCode Invert Binary Tree
- 226Invert Binary Tree
- LeetCode | Invert Binary Tree
- leetcode--Invert Binary Tree
- [leetcode] Invert Binary Tree
- [LeetCode] Invert Binary Tree
- LeetCode Invert Binary Tree
- Invert Binary Tree
- leetcode : Invert Binary Tree
- 226Invert Binary Tree
- Invert Binary Tree
- 最近比较忙...
- [Android]构建boot.img(一):root目录与ramdisk.img的生成
- IDEA使用指南
- 15名一大代表及中共早期两大袖领的命运
- Javascript判断一个数字是否在一个区间内
- LeetCode_ Invert Binary Tree
- orcal中id自增
- [Android]构建boot.img(三):boot.img的生成与结构
- jsp学习中遇到的问题
- 新年新感想0104-0108
- 人类基因组参考基因组
- Objective-C 6 NSMutableString的常用方法
- hdu1229——还是A+B
- Thinkphp框架中使用数据对象自动处理添加数据库数据时,关于在数据库表中添加新列时出现新列的数据添加不上去?