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 ...
随机推荐
- hive的常用HQL语句
1.过滤条件 where .limit. distinct. between and . null. is not nullselect * from emp where sal > 3000; ...
- 04构建之法读书笔记——IT行业的创新
IT行业的创新: 1.创新的迷思: 灵光一闪现,伟大的创新就紧随其后:大家都喜欢创新:好的想法会赢:创新者都是一马当先:要成为领域的专家,才能创新:技术的创新是关键:成功的团队更能创新 2.创新的时机 ...
- Tempter of the Bone HDU - 1010(dfs)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- P1309 瑞士轮
题目背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较低,但比赛过程往往十分 ...
- Python 信号处理 signal 模块
Table of Contents 1. signal模块简介 1.1. signal简单示例 1.2. signal说明 1.2.1. 基本的信号名 1.2.2. 常用信号处理函数 2. signa ...
- OpenCV学习笔记(七) 图像金字塔 阈值 边界
转自: OpenCV 教程 使用 图像金字塔 进行缩放 图像金字塔是视觉运用中广泛采用的一项技术.一个图像金字塔是一系列图像的集合 - 所有图像来源于同一张原始图像 - 通过梯次向下采样获得,直到达到 ...
- js中基础数据类型
变量声明 undefined //未定义只声明 var age; alert(name);function fc(a1,a2,a3) { //alert(a1); //alert(a2); //a ...
- System.AccessViolationException”类型的第一次机会异常在 System.Data.dll 中发生 其他信息: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
管理员cmd中运行 netsh winsock reset
- 43、gridview或者listview的adapter优化
1.在getview时,如果是一个textview,那么不用每次都new一个或者inflater直接返回,可以先判断convertview是否为空,如果为空则new或者inflate,否则直接返回co ...
- BZOJ 1864:[Zjoi2006]三色二叉树(树DP)
三色二叉树 问题描述 输入 仅有一行,不超过500000个字符,表示一个二叉树序列. 输出 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. 样例输入 1122002010 ...