Info

Same as Right View, just add left nodes first instead of right nodes.

class Solution {
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        if(root == null) return ans;
        
        Queue<TreeNode> q = new LinkedList<>();
        q.add(root);
 
        while(!q.isEmpty()){
            int size = q.size();
            ans.add(q.peek().val);
            
            for(int i = 0; i < size; i++){
                TreeNode curr = q.poll();
 
                if(curr.left != null){
                    q.add(curr.left);
                }
 
                if(curr.right != null){
                    q.add(curr.right);
                }
            }
        }
 
        return ans;
    }
}