Invert Binary Tree

class Solution {
	public TreeNode invertTree(TreeNode root) {
		//corner case 
		if (root == null) return root;
	
		//divide
		TreeNode left = invertTree(root.left);
	TreeNode right = invertTree(root.right);
	
	//conquer
	root.left = right;
	root.right = left;
	return root;
	}
}

最后更新于

这有帮助吗?