Conditions | 6 |
Paths | 8 |
Total Lines | 23 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
27 | public static function insertIntoBST2(?TreeNode $root, int $val): TreeNode |
||
28 | { |
||
29 | $curr = $root; |
||
30 | while ($curr instanceof TreeNode) { |
||
31 | if ($curr->val < $val) { |
||
32 | if (!$curr->right) { |
||
33 | $curr->right = new TreeNode($val); |
||
34 | return $root; |
||
|
|||
35 | } else { |
||
36 | $curr = $curr->right; |
||
37 | } |
||
38 | } |
||
39 | if ($curr->val > $val) { |
||
40 | if (!$curr->left) { |
||
41 | $curr->left = new TreeNode($val); |
||
42 | return $root; |
||
43 | } else { |
||
44 | $curr = $curr->left; |
||
45 | } |
||
46 | } |
||
47 | } |
||
48 | |||
49 | return new TreeNode($val); |
||
50 | } |
||
52 |