| Conditions | 6 |
| Paths | 6 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 34 | public static function bfsTreeValues(?TreeNode $tree): array |
||
| 35 | { |
||
| 36 | if (!$tree) { |
||
| 37 | return []; |
||
| 38 | } |
||
| 39 | $ans = $queue = []; |
||
|
|
|||
| 40 | $queue = [$tree]; |
||
| 41 | while ($queue) { |
||
| 42 | /** @var TreeNode $node */ |
||
| 43 | $node = array_shift($queue); |
||
| 44 | array_push($ans, $node->val ?: null); |
||
| 45 | if ($node->left) { |
||
| 46 | array_push($queue, $node->left); |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($node->right) { |
||
| 50 | array_push($queue, $node->right); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | return $ans; |
||
| 55 | } |
||
| 85 |