, 270 , .
:
public void insert(int val) {
if (root == null) {
nodes++;
root = new Node(val);
} else if (!root.exists(val)) {
root.insert(val);
}
}
exists(), :
boolean exists(int val) {
return val == this.elem
|| (val < this.elem ? (this.left != null && this.left.exists(val))
: (this.right != null && this.right.exists(val)));
}
, , , , , , , ! , 100 . , O (n ^ 2 * logn) , 100 - !
, exists().