> For the complete documentation index, see [llms.txt](https://ucan.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ucan.gitbook.io/notes/tree/226.-invert-binary-tree.md).

# 226. Invert Binary Tree

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