Invert Binary Tree

     4
   /   \
  2     7
 / \   / \
1   3 6   9

     4
   /   \
  7     2
 / \   / \
9   6 3   1


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

  

posted @ 2015-06-23 14:56  okay4321  阅读(131)  评论(0编辑  收藏  举报