| Conditions | 7 |
| Paths | 6 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public static function kthSmallest(TreeNode $root, int $k): int |
||
| 12 | { |
||
| 13 | if ($k <= 0) { |
||
| 14 | return 0; |
||
| 15 | } |
||
| 16 | $stack = []; |
||
| 17 | while ($root || $stack) { |
||
|
|
|||
| 18 | while ($root && $root->val) { |
||
| 19 | array_push($stack, $root); |
||
| 20 | $root = $root->left; |
||
| 21 | } |
||
| 22 | $root = array_pop($stack); |
||
| 23 | if (--$k === 0) { |
||
| 24 | break; |
||
| 25 | } |
||
| 26 | $root = $root->right; |
||
| 27 | } |
||
| 28 | |||
| 29 | return $root->val; |
||
| 30 | } |
||
| 55 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.