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. 【dp】守望者的逃离

    妙 题目描述 恶魔猎手尤迪安野心勃勃,他背着了暗夜精灵,率领深藏在海底的娜迦族企图叛变.守望者在与尤迪安的交锋中遭遇了围杀,被困在一个荒芜的大岛上.为了杀死守望者,尤迪安开始对这个荒岛施咒,这座岛很快 ...

  2. UVA - 11572 Unique Snowflakes 滑动扫描

    题目:点击打开题目链接 思路:从左往右扫描,定义扫描左端点L,右端点R,保证每次往几何中添加的都是符合要求的连续的数列中的元素,L和R从0扫到n,复杂度为O(n),使用set维护子数列,set查找删除 ...

  3. POJ:1753-Flip Game(二进制+bfs)

    题目链接:http://poj.org/problem?id=1753 Flip Game Time Limit: 1000MS Memory Limit: 65536K Description Fl ...

  4. UVA10779Collectors Problem

    uva 10779 Collectors Problem Some candy manufacturers put stickers into candy bar packages. Bob and ...

  5. IDEA字体颜色快速导入辅助工具设置

     原创链接:https://www.cnblogs.com/ka-bu-qi-nuo/p/9181954.html 程序员开发大多数都是使用IDE进行代码开发的,这样能快速的开发出需要的项目.之前一直 ...

  6. ogre3D学习基础11 -- 交换两个场景管理器

    这一节,练习一下前几次学习的内容,功能很简单,就是建立两个不同的场景管理器,当按下键盘上某个键时切换镜头. 基本框架不变,这个监听器继承了两个父类,一个是我们的老朋友ExampleFrameListe ...

  7. webdriver高级应用- 无人工干预地自动下载某个文件

    在网页上下载文件时,通常需要人为设定下载文件并选择保持路径,这样就无法实现完全自动的下载过程.下面实现基于firefox浏览器的全自动化文件下载操作: #encoding=utf-8 from sel ...

  8. Selenium WebDriver- actionchians模拟鼠标悬停操作

    #encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...

  9. selenium2.53用45以下的火狐别太高

    selenium2.53用45以下的火狐别太高在高的火狐需要selenium3

  10. xml报错“cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element”

    配置使用dubbo时,xml报错“cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be ...