interview fb2
2024-09-29 13:54:56
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;
}
最新文章
- Ubuntu 15.1 unity在顶部面板显示系统CPU/内存/网络速度
- 将jetty嵌入到应用中的简单案例
- 从excel文件中获取数据(2)
- Zepto中文API
- 【分布式协调器】Paxos的工程实现-Cocklebur状态转移
- LeetCode : 223. Rectangle Area
- JIRA系统部署推进上线流程
- 搭建高性能计算环境(七)、应用软件的安装之MS
- eclipse界面语言的切换方法
- C++ Code_combobox
- 作品第一课----获取批量checkbox选中的值
- Android菜鸟的成长笔记(7)——什么是Activity
- 由Find All References引发的思考。,
- VMWare、KVM、Virtualbox克隆或复制Linux虚拟机后eth0找不到的解决方案
- 多线程:head first Thread.join()
- 运算符(C# 参考)
- java表达式类型的自动提升
- Gitflow工作流程
- (后端)spring的@Transactional注解详细用法(转)
- javaMail简介(一)
热门文章
- 科学计算库Numpy——数组形状
- linux Ubuntu18.04 安装配置MySQL
- day 44 前端HTML
- B1020 月饼(25 分)
- [BZOJ1597][Usaco2008 Mar]土地购买(斜率优化)
- 笔记-python-selenium,phantomjs
- EF上下文对象创建之线程内唯一
- TCP/IP网络编程之多种I/O函数
- Python中__str__和__repr__的区别
- django 开发之模型以及静态问题和图片的使用