https://leetcode.com/problems/binary-tree-right-side-view


Success!

___


Others' opinion shouldn't affect you that much. Be you, talent alone.

___

Runtime
40 ms

Beats
78.27%

Memory
13.8 MB

Beats
98.61%

___


```python
class Solution:
    def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
        #2022/12/22 07:14 
        if root == None:
            return []
        
        a_list = [root]
        b_list = []
        switch_flag = 0
        level_list = []

        while True:
            if len(a_list) == 0 and len(b_list) == 0:
                break
            
            if switch_flag == 0:
                for node in a_list:
                    if node.left:
                        b_list.append(node.left)
                    if node.right:
                        b_list.append(node.right)
                level_list.append([n for n in a_list])
                a_list = []
                switch_flag = 1
            else:
                for node in b_list:
                    if node.left:
                        a_list.append(node.left)
                    if node.right:
                        a_list.append(node.right)
                level_list.append([n for n in b_list])
                b_list = []
                switch_flag = 0
        
        result_list = []
        for row in level_list:
            result_list.append(row[-1].val)

        return result_list
        #2022/12/22 07:58
```




