考察点

  • 广度优先遍历--层次遍历
  • 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. ThinkPHP第二十一天(JQuery元素获取,parents属性,toggle方法,确认弹出对话框使用)

    1.JQuery用法 A:$(function(){code...});表示当页面载入完毕后执行 B:获取元素方法:根据class名称 $('.classname'),根据ID名称 $('#IDnam ...

  2. [暂停一天]从零开始PHP学习 - 第六天

    今天这个系列没有时间去写了 在公司完善一个项目     已经备好6瓶咖啡 两天 + 一夜 完成这个项目  真是苦逼 诶 反正这几天 明白一个道理:别以为你多牛B 你不会的东西多了!  比你牛B的人也多 ...

  3. poj 3228 Gold Transportation 二分+网络流

    题目链接 给出n个城市, 每个城市有一个仓库, 仓库有容量限制, 同时每个城市也有一些货物, 货物必须放到仓库中. 城市之间有路相连, 每条路有长度. 因为有些城市的货物量大于仓库的容量, 所以要运到 ...

  4. maven打包成第三方jar包且把pom依赖包打入进来

    <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId& ...

  5. android方向键被锁定的问题

    当虚拟机启动的时候,很多情况是旁边的方向键不能点击,处于一种被锁定的状态,解决办法如下: 找到   C:\Users\Administrator(你的用户名)\.android\avd\mm.adv( ...

  6. WebRTC学习笔记_Demo收集

    1.     WebRTC学习 1.1   WebRTC现状 本人最早接触WebRTC是在2011年底,那时Google已经在Android源代码中增加了webrtc源代码,放在/external/w ...

  7. android媒体--图库与API层MediaPlayer的交互

    众所周知一个媒体播放器新建的几个步骤: Mediaplayer mp = new MediaPlayer(0 mp.setDatasource(xxx); mp.setDispalyer(xxx); ...

  8. oralce11g 注冊表卸载20140810

    Windows Registry Editor Version 5.00 [-HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE] [-HKEY_LOCAL_MACHINE\SOFT ...

  9. Hive索引

    1.        Hive索引概述 Hive的索引目的是提高Hive表指定列的查询速度. 没有索引时.类似'WHERE tab1.col1 = 10' 的查询.Hive会载入整张表或分区.然后处理全 ...

  10. superMap Object 属性查看的一点代码

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...