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 ...
随机推荐
- 关于js中onclick字符串传参问题(html="")
规则: 外变是“”,里面就是‘’外边是‘’,里边就是“” 示例: var a="111"; var html="<a onclick='selecthoods( ...
- 权限组件(15):rbac的使用文档和在业务中的应用
这里用主机管理系统当做示例. 一.将rbac组件拷贝到项目中. 注意: rbac自己的静态文件.layout.html(被继承的模板).bootstrap.fontsize.公共的css.jquery ...
- 动态规划:HDU1712-ACboy needs your help(分组背包问题)
ACboy needs your help Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- 二叉树的镜像(Python实现)
题目 给定一棵二叉树,要求输出其左右翻转后二叉树的中序遍历. 例: 翻转前: 翻转后: 1 | 1 / \ | / \ 2 3 | 3 2 / \ | / \ 4 5 | 5 4 解析 两个步骤: 镜 ...
- DiyCode开源项目 BaseActivity 分析
1.首先将这个项目的BaseActivity源码拷贝过来. /* * Copyright 2017 GcsSloop * * Licensed under the Apache License, Ve ...
- Android 显示和隐藏软键盘的方法
前言:因为项目要求做一个类似贴吧一样的东西,可以评论,所以必不可少地需要用到软键盘的隐藏和显示. Step 1 废话不多说,先上封装好的代码. public class CommonUtils ...
- leetcode 【 Minimum Path Sum 】python 实现
题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right w ...
- redhat linux 7.4关闭透明大页
每一步: 在GRUB_CMDLINE_LINUX加入选项 transparent_hugepage=never echo 'GRUB_CMDLINE_LINUX="transparent_h ...
- 在smarty模板中使用PHP函数的方法
在smarty模板中如果要在显示的资料使用php函数时,如果是只有一个参数的函数比如说去空白的trim会写成 sample1 代码如下: <{$colname|trim}> 那如果使用像i ...
- Struts2 改变语言状态
只要在请求中增加 request_locale=en_US 参数,就可以实现语言的切换,内部由拦截器实现