199. Binary Tree Right Side View
作者:互联网
The problem of this solution can be BFS and DFS.
BFS is easy to understand.
The following is DFS solution:
private List<Integer> res = new ArrayList<>(); public List<Integer> rightSideView(TreeNode root) { helper(root, 0); return res; } private void helper(TreeNode root, int level){ if(root==null) return; if(res.size()==level){ res.add(root.val); } helper(root.right, level+1); helper(root.left, level+1); }
标签:Binary,Right,199,helper,level,res,private,return,root 来源: https://www.cnblogs.com/feiflytech/p/15873558.html