/** 199. Binary Tree Right Side View * 11.21 by Mingyang * In the recursive algorithm, that is, sticking to the left edge of the tree to go down, if not to one side, and then continue to the right side, using the end of the number of layers equal to the skill Qiao * is actually a root right-left algorithm, very ingenious*/ PublicList<integer>Rightsideview (TreeNode root) {List<Integer> result =NewArraylist<integer>(); Rightsideview (root, result,0); returnresult; } Public voidRightsideview (TreeNode curr, list<integer> result,intcurrdepth) { if(Curr = =NULL){ return; } //here is the most subtle place, using the number of result numbers and layers equal to the method, such as root of the right subtree after the walk//On the left, when you first did not arrive at this condition, you continue to go down naturally . if(Currdepth = =result.size ()) {Result.add (curr.val); } rightsideview (Curr.right, result, currdepth-W); Rightsideview (Curr.left, result, currdepth-W); }
199. Binary Tree Right Side View