226. Invert Binary Tree
Invert Binary Tree
Solution
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public TreeNode invertTree(TreeNode root) {
if (root == null) return null;
TreeNode right = invertTree(root.left);
TreeNode left = invertTree(root.right);
root.left = left;
root.right = right;
return root;
}
}Last updated