Add One Row to Tree LeetCode solution in Java

1
class Solution {
2
public TreeNode addOneRow(TreeNode root, int v, int d) {
3
if (d == 1) return new TreeNode(v, root, null);
4
else if (d == 2) {
5
root.left = new TreeNode(v, root.left, null);
6
root.right = new TreeNode(v, null, root.right);
7
} else {
8
if (root.left != null) addOneRow(root.left, v, d - 1);
9
if (root.right != null) addOneRow(root.right, v, d - 1);
10
}
11
return root;
12
}
13
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0