Leetcode First brush _binary Tree level Order traversal II

Source: Internet
Author: User

Very easy title, at the back, I don't think it's so simple to answer more. We will write, no one.

Pre-order on the ground floor, plus save every layer, plus the output from the bottom up, is a vector and a stack so the problem, without him, but on the other hand-cooked Seoul.

Class Solution {public:vector<vector<int> > Levelorderbottom (TreeNode *root) {vector<vector<        int> > Res;        if (root = NULL) return res;        Queue<treenode*> que;        stack<vector<int> > S;        Vector<int> Tpres;        TreeNode *pnode;        Que.push (root);        Que.push (NULL);            while (!que.empty ()) {Pnode = Que.front ();            Que.pop ();                if (Pnode = = NULL) {s.push (tpres);                Tpres.clear ();                if (Que.empty ()) break;                    else{Que.push (NULL);                Continue            }} tpres.push_back (Pnode->val);            if (pnode->left) Que.push (pnode->left);        if (pnode->right) Que.push (pnode->right);            } while (!s.empty ()) {Res.push_back (S.top ());        S.pop (); } return Res; }};


Leetcode First brush _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.