leetcode_655. Print Binary Tree
https://leetcode.com/problems/print-binary-tree/
打印整棵二叉树
class Solution
{
public: int getTreeHeight(TreeNode* root)
{
return root==NULL?:max(getTreeHeight(root->left), getTreeHeight(root->right))+;
} vector<vector<string>> printTree(TreeNode* root)
{
int height = getTreeHeight(root);
vector<vector<string>> res(height, vector<string>((int)pow(, height)-,""));
dfs(root, , , pow(, height)-, res);
return res;
} void dfs(TreeNode* root, int layer, int l, int r, vector<vector<string>>& res)
{
if(root == NULL)
return;
int mid = (l+r)/;
stringstream ss;
string value;
ss<<root->val;
ss>>value;
res[layer][mid] = value;
dfs(root->left, layer+, l, mid-, res);
dfs(root->right, layer+, mid+, r, res);
}
};
leetcode_655. Print Binary Tree的更多相关文章
- LC 655. Print Binary Tree
Print a binary tree in an m*n 2D string array following these rules: The row number m should be equa ...
- [LeetCode] Print Binary Tree 打印二叉树
Print a binary tree in an m*n 2D string array following these rules: The row number m should be equa ...
- [Swift]LeetCode655. 输出二叉树 | Print Binary Tree
Print a binary tree in an m*n 2D string array following these rules: The row number m should be equa ...
- U面经Prepare: Print Binary Tree With No Two Nodes Share The Same Column
Give a binary tree, elegantly print it so that no two tree nodes share the same column. Requirement: ...
- LeetCode 655. Print Binary Tree (C++)
题目: Print a binary tree in an m*n 2D string array following these rules: The row number m should be ...
- [LeetCode] 655. Print Binary Tree 打印二叉树
Print a binary tree in an m*n 2D string array following these rules: The row number m should be equa ...
- 【LeetCode】655. Print Binary Tree 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://le ...
- Print Nodes in Top View of Binary Tree
Top view of a binary tree is the set of nodes visible when the tree is viewed from the top. Given a ...
- HDU 1710 Binary Tree Traversals(二叉树遍历)
传送门 Description A binary tree is a finite set of vertices that is either empty or consists of a root ...
随机推荐
- 添加和删除节点(HTML元素)
创建新的HTML元素 <div id="div1"> <p id="p1">这是一个段落</p> <p id=&quo ...
- Buildroot构建指南——根文件系统(Rootfs)【转】
本文转载自; 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] Buildroot构建指南——根文件系统(Rootfs) Buildroot的Rootfs构建流程有一个大 ...
- YTU 2887: D--机器人Bill
2887: D--机器人Bill 时间限制: 1 Sec 内存限制: 128 MB 提交: 112 解决: 22 题目描述 最近,Dr. Jiang 新设计一个机器人Bill.Bill很聪明,会做 ...
- ValueError: Some of types cannot be determined by the first 100 rows, please try again with sampling
ValueError: Some of types cannot be determined by the first 100 rows, please try again with sampling ...
- 并不对劲的p3709:大爷的字符串题
题目大意 区间众数 题解 莫队 代码 #include<algorithm> #include<cmath> #include<cstdio> #include&l ...
- http_load常见问题及解决方案
1.错误信息:byte count wrong http_load在处理时会去关注每次访问同一个URL返回结果(即字节数)是否一致,若不一致就会抛出byte count wrong 所以动态页面可以忽 ...
- DIV居中显示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Groupby 方法语法
对序列进行分类汇总,汇总后产生的序列的key就是按照某个字段汇总的项 .groupby select Viewmodel三者常一起使用,用于统计.groupby 方法语法常与select 子句形成数据 ...
- bzoj 1853: [Scoi2010]幸运数字&&2393: Cirno的完美算数教室【容斥原理】
翻了一些blog,只有我用状压预处理嘛2333,.把二进制位的0当成6,1当成8就行啦.(2393是2和9 然后\( dfs \)容斥,加上一个数的\( lcm \),减去两个数的\( lcm \), ...
- Git客户端使用教程
课程地址 <版本控制入门 – 搬进 Github> 笔记参考 <搬进 Github> Git客户端的使用 Git for windows下载 新建一个仓库tata,使用subl ...