Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given the following binary tree,
* Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ publicclass{ public List<Integer> rightSideView(TreeNode root){ List<Integer> ans = new ArrayList<Integer>(); helper(root, 0, ans); return ans; }
publicvoidhelper(TreeNode root, int j, List<Integer> ans){
近期评论