将一个二叉树左右翻转(Java 版)

public class Solution 
{
  public TreeNode invertTree(TreeNode root) 
  {
    if (root == null) 
    {
      return null;
    }
    root.left = invertTree(root.left);
    root.right = invertTree(root.right);

    TreeNode tmp = root.left;
    root.left = root.right;
    root.right = tmp;
    return root;
  }
}

 

posted @ 2016-03-28 17:54  ~小小鸟~  阅读(928)  评论(0编辑  收藏  举报