数据结构:树🌲
时间复杂度:O(n)
空间复杂度:O(n)
代码实现:
class Solution:def rightSideView(self, root: Optional[TreeNode]) -> List[int]:if not root: return []q = [root]res = []while q:out = Nonefor _ in range(len(q)):out = q.pop(0)if out.left:q.append(out.left)if out.right:q.append(out.right)res.append(out.val)return res