Lintcode 175. 翻转二叉树
2017-01-01 23:51
281 查看
--------------------
递归那么好为什么不用递归啊...我才不会被你骗...(其实是因为用惯了递归啰嗦的循环反倒不会写了...o(╯□╰)o)
AC代码:
/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * } * } */ public class Solution { /** * @param root: a TreeNode, the root of the binary tree * @return: nothing */ public void invertBinaryTree(TreeNode root) { if(root==null) return ; TreeNode t=root.left; root.left=root.right; root.right=t; invertBinaryTree(root.left); invertBinaryTree(root.right); } }
题目来源: http://www.lintcode.com/zh-cn/problem/invert-binary-tree/
相关文章推荐
- 【LintCode 简单】175. 翻转二叉树
- [LintCode]175.翻转二叉树
- LintCode_175_翻转二叉树
- 翻转二叉树-LintCode
- [LintCode] Invert Binary Tree 翻转二叉树
- lintcode ----翻转二叉树
- LintCode-翻转二叉树
- LintCode --invert-binary-tree(翻转二叉树)
- 175. 翻转二叉树
- Lintcode---翻转二叉树
- lintcode 翻转二叉树
- 175. 翻转二叉树--java
- 翻转二叉树-LintCode
- LintCode 翻转二叉树
- LintCode--翻转二叉树(非递归)
- lintcode 容易题:Invert Binary Tree 翻转二叉树
- [Lintcode] #175 翻转二叉树
- [LintCode] 翻转二叉树
- LintCode 翻转二叉树
- LintCode 翻转二叉树