考察点

  • 广度优先遍历--层次遍历
  • STL内容器的用法

广度优先遍历的时候,首先应该想到的就是借助于队列。还需要在遍历下一层之前保存当前层节点的数量

代码很简单:

class Solution {
public:
vector<vector<int> > levelOrderBottom(TreeNode* root) {
vector<vector<int> >vec;
if(root==NULL){
return vec;
}
queue <TreeNode *>qu;
qu.push(root);
int count=;//保存每一层的节点数量 while(!qu.empty()){
vector <int> v;
while(count>=){
TreeNode *node; node=qu.front();
qu.pop();
v.push_back(node->val);
count--;
if(node->left!=NULL){
qu.push(node->left);
}
if(node->right!=NULL){
qu.push(node->right);
}
}
vec.insert(vec.begin(),v);
count=qu.size();
} }
};

Binary Tree Level Order Traversal II --leetcode C++的更多相关文章

  1. Binary Tree Level Order Traversal II——LeetCode

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

  2. Binary Tree Level Order Traversal II [LeetCode]

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

  3. Binary Tree Level Order Traversal II leetcode java

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

  4. 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 ...

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

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

  8. 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 ...

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

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

随机推荐

  1. ios本地文件内容读取,.json .plist 文件读写

    ios本地文件内容读取,.json .plist 文件读写 本地文件.json .plist文件是较为常用的存储本地数据的文件,对这些文件的操作也是一种常用的基础. 本文同时提供初始化变量的比较标准的 ...

  2. 使用 UML 进行业务建模:理解业务用例与系统用例的相似和不同之处

    使用 UML 进行业务建模:理解业务用例与系统用例的相似和不同之处   作者:Arthur V. English 出处:IBM   本文内容包括: 背景 业务用例模型与系统用例模型有什么相似之处? 业 ...

  3. ASP.NET MVC 必备知识点杂谈

    一  工程结构4个程序集 Microsoft.Web.Mvc --一些可以使用的,不确定的程序包System.Web.Mvc  --主程序库下面两个列入3.5的Net框架了System.Web.Abs ...

  4. 深度优先搜索——迷宫问题(华为oj)

    题目描述: 定义一个二维数组N*M(其中2<=N<=10;2<=M<=10),如5 × 5数组下所示: int maze[5][5] = { 0, 1, 0, 0, 0, 0, ...

  5. font awesome使用笔记

    背景 今天将BS项目部署到IIS服务器上时.首次打开一个使用font awesome图标集的页面是加载非常慢. 于是果断按下F12查看具体页面的请求时常.除去其他异步数据的加载消耗时间以外.我居然看到 ...

  6. Android 利用摄像头指尖测试心率

    过摄像头来获得心率,搜了一下这个技术真不是噱头,据说在iPhone早有实现,主要原理是:当打开软件时,手机的闪光灯也会被自动打开,用户将手指放在摄像头上时,指尖皮下血管由于有血液被压入,被光源照射的手 ...

  7. bzoj 1088: [SCOI2005]扫雷Mine

    题目链接 1088: [SCOI2005]扫雷Mine Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2525  Solved: 1495[Submi ...

  8. ZOJ 3209 Treasure Map 精确覆盖

    题目链接 精确覆盖的模板题, 把每一个格子当成一列就可以. S忘记初始化TLE N次, 哭晕在厕所...... #include<bits/stdc++.h> using namespac ...

  9. 0617 python 基础04

    控制流--for 循环 >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 换行输出 >>> for i in range(1 ...

  10. checkbox 全选反选实现全代码

    //跳转到指定action function validateForm(url){ if($("#form").form('validate')){ var x=document. ...