您的位置:首页 > 其它

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/

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: