http://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/

树的层序遍历,和上一道题相比,对结果做一个顺序调整 reverse()

/**
* Definition for binary tree
* 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) {
vector<vector<int> > ans;
if(root == NULL)
return ans;
int num = ,num2 = ,nullNum = ,nullNumAcc = ;
queue<TreeNode *> myQueue;
myQueue.push(root);
TreeNode *nodeFront; vector<int> onePiece;
while(!myQueue.empty())
{
nodeFront = myQueue.front();
myQueue.pop();
num--; onePiece.push_back(nodeFront->val);
if(nodeFront->left)
myQueue.push(nodeFront->left);
else
nullNum++;
if(nodeFront->right)
myQueue.push(nodeFront->right);
else
nullNum++; if(num == )
{
if(onePiece.empty())
break;
ans.push_back(onePiece);
onePiece.clear();
num2 = num2*;
nullNumAcc = nullNumAcc* + nullNum;
num = num2 - nullNumAcc;
nullNum = ;
}
}
reverse(ans.begin(),ans.end());
return ans;
}
};

LeetCode OJ--Binary Tree Level Order Traversal II的更多相关文章

  1. Java for LeetCode 107 Binary Tree Level Order Traversal II

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

  2. LeetCode 107 Binary Tree Level Order Traversal II(二叉树的层级顺序遍历2)(*)

    翻译 给定一个二叉树,返回从下往上遍历经过的每一个节点的值. 从左往右,从叶子到节点. 比如: 给定的二叉树是 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回它从下 ...

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

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

  4. (二叉树 BFS) leetcode 107. Binary Tree Level Order Traversal II

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

  5. 【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 ...

  6. LeetCode 107. Binary Tree Level Order Traversal II (二叉树阶层顺序遍历之二)

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

  7. [leetcode] 7. Binary Tree Level Order Traversal II

    这次相对来讲复杂点,题目如下: Given a binary tree, return the bottom-up level order traversal of its nodes' values ...

  8. leetcode 107 Binary Tree Level Order Traversal II ----- java

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

  9. LeetCode 107. Binary Tree Level Order Traversal II

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

  10. Java [Leetcode 107]Binary Tree Level Order Traversal II

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

随机推荐

  1. Linux - which xxx - 查找执行的命令所在的路径

    Linux 下,我们常使用 cd ,grep,vi 等命令,有时候我们要查到这些命令所在的位置,如何做呢? Linux 下有2个命令可完成该功能:which ,whereis which 用来查看当 ...

  2. centos 7 忘记root 密码

    @@@@首先开启系统,出现下图界面以后,按e键. @@@使用下放下箭头找到图中的位置,在下图中 修改 ro 为 rw , 添加init=sysroot/bin/sh @@@按Ctrl + x 进入单用 ...

  3. 如何用纯 CSS 创作一个过山车 loader

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/KBxYZg/ 可交互视频 此视频是 ...

  4. graph-Dijkstra's shortest-path alogorithm

    直接贴代码吧,简明易懂. 后面自己写了测试,输入数据为: a b c d e 0 1 4 0 2 2 1 2 3 1 3 2 1 4 3 2 1 1 2 3 4 2 4 5 4 3 1 也就是课本上1 ...

  5. CodeForces 519E 树形DP A and B and Lecture Rooms

    给出一棵树,有若干次询问,每次询问距两个点u, v距离相等的点的个数. 情况还挺多的,少侠不妨去看官方题解.^_^ #include <iostream> #include <cst ...

  6. android:exported属性

    这个属性用于指示该服务是否能够被其他应用程序组件调用或跟它交互.如果设置为true,则能够被调用或交互,否则不能.设置为false时,只有同一个应用程序的组件或带有相同用户ID的应用程序才能启动或绑定 ...

  7. JS实现——计算两日期之差

    在网上找了个js实现的,根据相差天数计算日期和根据两个日期计算相差多少天的示例和代码: 根据相差天数计算日期: 距离: 年 月 日 相差: 天 (输入负数则往前计算) 日期是:   根据日期计算相差天 ...

  8. Redhat7配置yum源(本地源和网络源)

    Redhat7配置yum源(本地源和网络源)   目录 一:配置本地yum源 二:配置网络yum源 YUM(Yellow dog Updater Modified): yum是基于RPM包构建的软件更 ...

  9. day04_05 逻辑运算符、表达式

    num += 1 等价于 num = num + 1 逻辑运算符 and   全true则true 条件1 and 条件2 5>3 and 3>2   ===> true 5> ...

  10. 编译TensorFlow CPU指令集优化版

    编译TensorFlow CPU指令集优化版 如题,CPU指令集优化版,说的是针对某种特定的CPU型号进行过优化的版本.通常官方给的版本是没有针对特定CPU进行过优化的,有网友称,优化过的版本相比优化 ...