Leetcode-binary Tree level Order traversal II

Source: Internet
Author: User

reverse the list of the last similar topic.

/** * Definition for Binary tree * public class TreeNode {* int val, * TreeNode left, * TreeNode right; TreeNode (int x) {val = x;} *} */public class Solution {public list<list<integer>> Levelorderbottom (Tre        Enode root) {list<list<integer>> List = new arraylist<> ();        list<list<integer>> trlist = new arraylist<> ();        BFS (0, Root, list);        for (int i=list.size ()-1; i>=0; i--) {Trlist.add (List.get (i));    } return trlist;        } public void BFs (int pos, TreeNode root, list<list<integer>> List) {if (root==null) return;        if (List.size () > pos) {list.get (POS). Add (Root.val);            } else {list<integer> L = new arraylist<> ();            L.add (Root.val);        List.add (l);        } BFS (pos+1, Root.left, list);    BFS (pos+1, root.right, list); }}

Leetcode-binary Tree level Order traversal II

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.