[LeetCode]: 226:Invert Binary Tree

题目:

Invert a binary tree.

     4
   /   
  2     7
 /    / 
1   3 6   9

to

     4
   /   
  7     2
 /    / 
9   6 3   1

Trivia:

分析:

简单的递归或者广度优先搜索就行

代码:

递归方法

    public TreeNode invertTree(TreeNode root) {
        
        if(root ==null){
            return null;
        }
        else{
            TreeNode NodeLeftTemp = invertTree(root.right); 
            TreeNode NodeRightTemp = invertTree(root.left); 
            root.left = NodeLeftTemp;
            root.right = NodeRightTemp;
            return root;
        }
    }
原文地址:https://www.cnblogs.com/savageclc26/p/4799379.html