class Solution {
List<Integer> list;
public List<Integer> rightSideView(TreeNode root) {
list = new LinkedList<>();
rightSideView(root, 0);
return list;
}
private void rightSideView(TreeNode root, int d) {
if (root == null) return;
if (d++ == list.size()) list.add(root.val);
rightSideView(root.right, d);
rightSideView(root.left, d);
}
}