leetcode invert-binary-tree

题目太容易了链接https://leetcode.com/problems/invert-binary-tree/

 class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
 }


public class Solutioninverttree {
     public TreeNode invertTree(TreeNode root) {

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

你可能感兴趣的:(leetcode invert-binary-tree)