interview fb2
2014.7.8fb
#include <iostream>
using namespace std; struct TreeNode{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int val)
{
left = NULL;
right = NULL;
}
}; /* Input : binary tree A
/ \
B C
/ \ \
D E G
\ \
F H Output :
A
BC
DEG
FH
*/
vector<vector<int> > transform(TreeNode *root)
{
vector<vector<int> ans;
if(root == NULL)
return ans; vector<int> ans_piece;
queue<TreeNode *> last_time; queue.push_back(root);
TreeNode *temp; vector<int> num_each;
num_each.push_back();
num_each.push_back();
int level = ;
while(queue.empty() == false)
{
num_each[level]--; temp = queue.get_first_one();
queue.pop();
if(temp)
ans_piece.push_back(temp->val);
if(temp->left)
{
queue.push_back(temp->left);
num_each[level+]++;
}
if(temp->right)
{
queue.push_back(temp->right);
num_each[level+]++;
} if(num_each[level] == )
{
ans.push_back(ans_piece);
level++;
ans_piece.clear();
num_each.push_back();
}
}
return ans;
}
interview fb2的更多相关文章
- Pramp mock interview (4th practice): Matrix Spiral Print
March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...
- WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】
http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...
- WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】
http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...
- Amazon Interview | Set 27
Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...
- Java Swing interview
http://www.careerride.com/Swing-AWT-Interview-Questions.aspx Swing interview questions and answers ...
- Pramp - mock interview experience
Pramp - mock interview experience February 23, 2016 Read the article today from hackerRank blog on ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- [译]Node.js Interview Questions and Answers (2017 Edition)
原文 Node.js Interview Questions for 2017 什么是error-first callback? 如何避免无止境的callback? 什么是Promises? 用什么工 ...
- WCF学习系列三--【WCF Interview Questions – Part 3 翻译系列】
http://www.topwcftutorials.net/2012/10/wcf-faqs-part3.html WCF Interview Questions – Part 3 This WCF ...
随机推荐
- [译]The Python Tutorial#11. Brief Tour of the Standard Library — Part II
[译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中 ...
- CSS-标准盒模型 & 怪异盒模型
CSS中Box model分类 CSS中Box model是分为两种:: W3C标准 和 IE标准盒子模型. 大多数浏览器采用W3C标准模型,而IE中则采用Microsoft自己的标准. 怪异模式是“ ...
- Nearest Common Ancestors POJ - 1330 (LCA)
Nearest Common Ancestors Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 34657 Accept ...
- 二叉树的镜像(Python实现)
题目 给定一棵二叉树,要求输出其左右翻转后二叉树的中序遍历. 例: 翻转前: 翻转后: 1 | 1 / \ | / \ 2 3 | 3 2 / \ | / \ 4 5 | 5 4 解析 两个步骤: 镜 ...
- 快速排序算法(C)
sort快排函数的基本版,效率n*logn,快排的完全版就是在递归之中夹杂对序列的预判断,最优的选择排序方法,快速排序算法只是其中之一. 简单的说明一下快速排序的思想,对于一个数列,首先选择一个基数( ...
- 洛谷P1067 多项式输出
题目链接:https://www.luogu.org/problemnew/show/P1067 这是一个纯模拟的小怪但是需要注意一些小细节: 1.首项为正没有+号. 2.所有项系数如果是一的话就省略 ...
- Storm Ack容错机制
- Eclipse 读取config目录下文件
最近在一个项目,在项目下新建了一个config配置文件夹,添加一个配置文件config.properties. 使用classpath:config.properties方式加载配置文件, 具体实现代 ...
- Google Optimize 安装使用教程
Google Optimize 介绍 打开链接 https://optimize.google.com/optimize/signup/ 填入电邮地址后等待注册邀请 Google Optimize是什 ...
- git和github基础入门
一.git: 1.安装配置git: 1.1从官网或者该网址处下载:https://pan.baidu.com/s/1kU5OCOB#list/path=%2Fpub%2Fgit 1.2安装,一路nex ...