# 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; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up