LeetCode_ Invert Binary Tree
来源:互联网 发布:域名添加a记录 编辑:程序博客网 时间:2024/06/01 08:05
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; }}注释部分提交后会出现空指针错误。使用了递归的思想,有较强的借鉴意义!
1 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
- LeetCode——Nim Game
- LeetCode__Add Digits
- Leetcode__Maximum depth
- LeetCode_237. Delete Node in a Linked List
- leetCode_Move Zeroes_
- LeetCode_ Invert Binary Tree
- LeetCode_SameTree
- Leetcode——valid Anagram——时间复杂度太高,怎么办??
- leetcode_Excel Sheet Column Number
- Leetcode——Contains Duplicate
- ORACLE-019:ORACLE常用SQL优化hint语句
- Android开发中BUG、错误汇总(不断更新)
- 基于SEDA的异步框架设计与实现
- wchar_t