| Total Complexity | 13 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class KthSmallestElementInABST |
||
| 10 | { |
||
| 11 | public static function kthSmallest(TreeNode $root, int $k): int |
||
| 30 | } |
||
| 31 | |||
| 32 | public static function kthSmallest2(TreeNode $root, int $k): int |
||
| 33 | { |
||
| 34 | if ($k <= 0) { |
||
| 35 | return 0; |
||
| 36 | } |
||
| 37 | $n = 0; |
||
| 38 | self::helper($root, $k, $n); |
||
| 39 | |||
| 40 | return $n; |
||
| 41 | } |
||
| 42 | |||
| 43 | private static function helper(?TreeNode $node, int &$k, int &$n) |
||
| 52 | } |
||
| 53 | } |
||
| 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.