Skip to content

Commit eea6d87

Browse files
authored
Create 226. Invert Binary Tree.java
1 parent 669006e commit eea6d87

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// O(n)
2+
3+
class Solution {
4+
public TreeNode invertTree(TreeNode root) {
5+
if (root == null) return null;
6+
7+
TreeNode temp = root.left;
8+
root.left = root.right;
9+
root.right = temp;
10+
11+
invertTree(root.left);
12+
invertTree(root.right);
13+
return root;
14+
}
15+
}

0 commit comments

Comments
 (0)