Binary Tree Right Side View

public List<Integer> rightSideView(TreeNode root) {

return rightSideViewBFS(root);
}

private List<Integer> rightSideViewBFS(TreeNode root){

List<Integer> result = new ArrayList<Integer>();

if(root==null){
return result;
}

Queue<TreeNode> queue = new LinkedList<TreeNode>();

queue.add(root);

while(queue.size() != 0){
int size = queue.size();

for (int i=0; i<size; i++) {

TreeNode node = queue.remove();

if(i==0){
result.add(node.val);
}

if(node.right!=null){
queue.add(node.right);
}

if(node.left!=null){
queue.add(node.left);
}

}
}

return result;

}