您的位置:首页 > 其它

Invert Binary Tree

2016-07-10 12:32 225 查看
Invertabinarytree.

Example

11
/\/\
23=>32
/\
44


/**
*DefinitionofTreeNode:
*publicclassTreeNode{
*publicintval;
*publicTreeNodeleft,right;
*publicTreeNode(intval){
*this.val=val;
*this.left=this.right=null;
*}
*}
*/
publicclassSolution{
/**
*@paramroot:aTreeNode,therootofthebinarytree
*@return:nothing
*/
publicvoidinvertBinaryTree(TreeNoderoot){
//writeyourcodehere
if(root==null)return;

TreeNodeleft=root.left;
root.left=root.right;
root.right=left;

invertBinaryTree(root.left);
invertBinaryTree(root.right);
}
}



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