Invert Binary Tree LeetCode solution in Java

1
class Solution {
2
public TreeNode invertTree(TreeNode root) {
3

4
swap(root);
5
return root;
6
}
7

8
private static void swap(TreeNode current) {
9
if (current == null) {
10
return;
11
}
12

13
swap(current.left);
14
swap(current.right);
15

16
TreeNode temp = current.left;
17
current.left = current.right;
18
current.right = temp;
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0