Invert Binary Tree

题目链接地址

// Definition for a binary tree node.
class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;
     TreeNode(int x) { val = x; }
 }

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


你可能感兴趣的:(Invert Binary Tree)