Insert into a Binary Search Tree LeetCode solution in Java

1
class Solution {
2
public TreeNode insertIntoBST(TreeNode root, int val) {
3
if (root == null) return new TreeNode(val);
4

5
if (root.val > val) root.left = insertIntoBST(root.left, val);
6
else root.right = insertIntoBST(root.right, val);
7

8
return root;
9
}
10
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0