| Conditions | 9 |
| Paths | 12 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public static function rightSideView(?TreeNode $root): array |
||
| 12 | { |
||
| 13 | if (!$root) { |
||
| 14 | return []; |
||
| 15 | } |
||
| 16 | $ans = $queue = []; |
||
|
|
|||
| 17 | $queue = [$root]; |
||
| 18 | while ($queue) { |
||
| 19 | $n = count($queue); |
||
| 20 | for ($i = 0; $i < $n; $i++) { |
||
| 21 | /** @var \leetcode\util\TreeNode $node */ |
||
| 22 | $node = array_shift($queue); |
||
| 23 | if ($node instanceof TreeNode) { |
||
| 24 | if ($i === $n - 1 && $node->val) { |
||
| 25 | array_push($ans, $node->val); |
||
| 26 | } |
||
| 27 | if ($node->left) { |
||
| 28 | array_push($queue, $node->left); |
||
| 29 | } |
||
| 30 | if ($node->right) { |
||
| 31 | array_push($queue, $node->right); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | return $ans; |
||
| 38 | } |
||
| 63 |