Skip to content

Latest commit

 

History

History
19 lines (16 loc) · 430 Bytes

199. 二叉树的右视图.md

File metadata and controls

19 lines (16 loc) · 430 Bytes
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);
    }
}