1. Binary Tree Level Order Traversal II My Submissions QuestionEditorial Solution

    Total Accepted: 79742 Total Submissions: 234887 Difficulty: Easy

    Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).

For example:

Given binary tree {3,9,20,#,#,15,7},

3

/ \

9 20

/ \

15 7

return its bottom-up level order traversal as:

[

[15,7],

[9,20],

[3]

]

思路:

参看前一篇

只要用栈存储即可,然后倒入顺序容器中

http://blog.csdn.net/justdoithai/article/details/51346177

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<vector<int>> levelOrderBottom(TreeNode* root) {
stack<vector<int>> res;
vector<vector<int>> res1;
if(root==NULL)return res1;
queue<TreeNode*> levelnode;
vector<int> row;
levelnode.push(root);
while(!levelnode.empty()){
queue<TreeNode*> pre;
vector<int> tmp;
while(!levelnode.empty()){
TreeNode * treetmp=levelnode.front();
levelnode.pop();
tmp.push_back(treetmp->val);
if(treetmp->left!=NULL)pre.push(treetmp->left);
if(treetmp->right!=NULL)pre.push(treetmp->right);
}
res.push(tmp);
levelnode = pre;
}
while(!res.empty()){
res1.push_back(res.top());
res.pop();
}
return res1;
}
};

63. Binary Tree Level Order Traversal II的更多相关文章

  1. 35. Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II

    Binary Tree Level Order Traversal OJ: https://oj.leetcode.com/problems/binary-tree-level-order-trave ...

  2. Binary Tree Level Order Traversal,Binary Tree Level Order Traversal II

    Binary Tree Level Order Traversal Total Accepted: 79463 Total Submissions: 259292 Difficulty: Easy G ...

  3. LeetCode之“树”:Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II

    Binary Tree Level Order Traversal 题目链接 题目要求: Given a binary tree, return the level order traversal o ...

  4. 102/107. Binary Tree Level Order Traversal/II

    原文题目: 102. Binary Tree Level Order Traversal 107. Binary Tree Level Order Traversal II 读题: 102. 层序遍历 ...

  5. 【LeetCode】107. Binary Tree Level Order Traversal II (2 solutions)

    Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal ...

  6. LeetCode_107. Binary Tree Level Order Traversal II

    107. Binary Tree Level Order Traversal II Easy Given a binary tree, return the bottom-up level order ...

  7. [LeetCode] Binary Tree Level Order Traversal II 二叉树层序遍历之二

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  8. 【Binary Tree Level Order Traversal II 】cpp

    题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...

  9. Binary Tree Level Order Traversal II 解题思路

    思路: 与Binary Tree Level Order Traversal I 几乎一样.只是最后将结果存放在栈里,然后在栈里再传给向量即可. 再次总结思路: 两个queue,先把第一个放进q1,循 ...

随机推荐

  1. HTML bootstrap 模态对话框添加用户

    HTML 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> ...

  2. vim 打开文件的常用操作

    一.如果在终端中开没有打开vim,可以: 横向分割显示: $ vim -o filename1 filename2 纵向分割显示: $ vim -O filename1 filename2 二.如果已 ...

  3. Laravel/Lumen 分组求和问题 where groupBy sum

    在Laravel中使用分组求和,如果直接使用Laravel各数据库操作方法,应该会得出来如下代码式: DB::table('table_a') ->where('a','=',1) ->g ...

  4. .Net Core微服务——网关(2):ocelot集成consul

    有consul基础的都知道,consul可以发现新增的服务,剔除掉无效的服务,赋予应用自动伸缩的能力.而ocelot如果集成了consul,那ocelot也能拥有这些能力,还可以自主选择负载均衡策略, ...

  5. Typecho 反序列化漏洞 分析及复现

    0x00 漏洞简介 CVE-2018-18753 漏洞概述: typecho 是一款非常简洁快速博客 CMS,前台 install.php 文件存在反序列化漏洞,通过构造的反序列化字符串注入可以执行任 ...

  6. PTA 7-2 畅通工程之局部最小花费问题 (35分)

    PTA 7-2 畅通工程之局部最小花费问题 (35分) 某地区经过对城镇交通状况的调查,得到现有城镇间快速道路的统计数据,并提出"畅通工程"的目标:使整个地区任何两个城镇间都可以实 ...

  7. 『学了就忘』Linux基础命令 — 37、Linux中挂载操作的相关命令

    目录 1.mount命令介绍 (1)mount命令说明 (2)mount命令格式 2.mount命令示例 3.mount -a命令说明 4.-o特殊选项说明 5.exec/noexec选项说明 挂载就 ...

  8. sqlalchemy create single table

    User.__table__.drop(engine) User.__table__.create(engine) https://stackoverflow.com/a/45287771/80250 ...

  9. 推荐一款颜值逆天且功能齐全的开源Shell工具!

    前言 以前在windows上一直使用的SSH工具是XShell,后来转到mac平台,XShell没有mac版本.所以之前一直在找一款颜值高,功能齐全的可以作为日常使用的Shell工具. 我知道mac下 ...

  10. SuperEdge再添国产智能加速卡支持,为边缘智能推理再提速10倍

    作者 寒武纪AE团队,腾讯云容器中心边缘计算团队,SuperEdge 开发者 SuperEdge 支持国产智能加速卡寒武纪 MLU220 SuperEdge 对应的商业产品 TKE Edge 也一直在 ...