Right View Tree
Problem Statement
Given a Binary Tree, print Right view of it. LeetCode link
Code
Python Code
class Solution:
def rightView(root):
if root is None:
return [root.value]
level = [] # leafs
queue = [root] # parents
res = []
while queue != []:
for node in queue:
if node.left:
level.append(node.left)
if node.right:
level.append(node.right)
res.append(node.value)
queue = level
level = [] # clear the leaf nodes
return res