| 31 | # self.right = None |
| 32 | |
| 33 | class Solution(object): |
| 34 | def rightSideView(self, root): |
| 35 | """ |
| 36 | :type root: TreeNode |
| 37 | :rtype: List[int] |
| 38 | """ |
| 39 | if not root: |
| 40 | return [] |
| 41 | |
| 42 | result = [root.val] |
| 43 | |
| 44 | current = [root] |
| 45 | next_nodes = [] |
| 46 | |
| 47 | while current or next_nodes: |
| 48 | for i in current: |
| 49 | if i.left: |
| 50 | next_nodes.append(i.left) |
| 51 | if i.right: |
| 52 | next_nodes.append(i.right) |
| 53 | if next_nodes: |
| 54 | |
| 55 | result.append(next_nodes[-1].val) |
| 56 | current = next_nodes |
| 57 | next_nodes = [] |
| 58 | |
| 59 | return result |
| 60 |
nothing calls this directly
no outgoing calls
no test coverage detected