---
# System prepended metadata

title: 0199. Binary Tree Right Side View
tags: [Leetcode, BFS, FaceBook, DFS, Medium]

---

# 0199. Binary Tree Right Side View
###### tags: `Leetcode` `FaceBook` `Medium` `BFS` `DFS`
Link: https://leetcode.com/problems/binary-tree-right-side-view/
## 思路
可以参考102题层序遍历的解法~
## Code
```java=
class Solution {
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        if(root==null) return res;
        Queue<TreeNode> q = new LinkedList<TreeNode>();
        q.offer(root);
        while(!q.isEmpty()){
            int currSize = q.size();
            for(int i = 0;i < currSize;i++){
                TreeNode node = q.poll();
                if(node.left!=null){
                    q.offer(node.left);
                }
                if(node.right!=null){
                    q.offer(node.right);
                }
                if(i == currSize-1){
                    res.add(node.val);
                }
            }
        }
        return res;
    }
}
```