"""Leetcode 199. Binary Tree Right Side View
Medium

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

Given a binary tree, imagine yourself standing on the right side of it,
return the values of the nodes you can see ordered from top to bottom.

Example:
Input: [1,2,3,null,5,null,4]
Output: [1, 3, 4]
Explanation:
   1            <---
 /   \
2     3         <---
 \     \
  5     4       <---
"""

# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None


class Solution(object):
    def rightSideView(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        pass
        

def main():
    pass


if __name__ == '__main__':
    main()

@@ -588,16 +588,34 @@
 Solution
+LevelTraversalLast
 (object)
@@ -722,63 +722,1128 @@
 nt%5D%0A
-        %22%22%22%0A        pass%0A        %0A%0Adef main():%0A    pass
+%0A        Time complexity: O(n).%0A        Space complexity: O(n).%0A        %22%22%22%0A        from collections import deque%0A%0A        # Base case.%0A        if not root:%0A            return %5B%5D%0A%0A        # Apply level traversal to collect visible values from top to bottom.%0A        visible_vals = %5B%5D%0A%0A        queue = deque(%5Broot%5D)%0A        while queue:%0A            size = len(queue)%0A            for i in range(size):%0A                current = queue.pop()%0A                if i == size - 1:%0A                    visible_vals.append(current.val)%0A%0A                # Add current's left or right to queue if existed.%0A                if current.left:%0A                    queue.appendleft(current.left)%0A                if current.right:%0A                    queue.appendleft(current.right)%0A%0A        return visible_vals%0A%0A%0Adef main():%0A    # Input:%0A    #    1%0A    #  /   %5C%0A    # 2     3%0A    #  %5C     %5C%0A    #   5     4%0A    # Output: %5B1, 3, 4%5D%0A    root = TreeNode(1)%0A    root.left = TreeNode(2)%0A    root.right = TreeNode(3)%0A    root.left.right = TreeNode(5)%0A    root.right.right = TreeNode(4)%0A%0A    print SolutionLevelTraversalLast().rightSideView(root)
 %0A%0A%0Ai

Complete level traversal last sol