199. Binary Tree Right Side View

Source: Internet
Author: User

    /** 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.