当前位置:网站首页>606. Create a string from a binary tree (video explanation!!!)
606. Create a string from a binary tree (video explanation!!!)
2022-07-30 09:53:00 【Learning to pursue high efficiency】
13. (有视频)前序遍历二叉树 转成 字符串
Preorder traversal of binary tree to string
public String tree2str(TreeNode root) {
StringBuilder sb = new StringBuilder();
tree2strChild(root,sb);
return sb.toString();
}
private void tree2strChild(TreeNode t,StringBuilder sb) {
if(t == null) return ;
sb.append(t.val);
if(t.left != null) {
sb.append("(");
tree2strChild(t.left,sb);
sb.append(")");
}else {
if(t.right == null) {
return;
}else{
sb.append("()");
}
}
if(t.right == null) {
return;
}else{
sb.append("(");
tree2strChild(t.right,sb);
sb.append(")");
}
}
边栏推荐
- 虚幻引擎图文笔记:could not be compiled. Try rebuilding from source manually.问题的解决
- 聊聊 MySQL 事务二阶段提交
- Concise Notes on Integrals - Types of Curve Integrals of the Second Kind
- debian10安装djando
- 企业数字化建设,自研还是采购?
- 实战演练 | 在 MySQL 中计算每日平均日期或时间间隔
- HR团队如何提升效率?人力资源RPA给你答案
- 函数式接口&Lambda表达式——简单应用笔记
- 如何避免CMDB沦为数据孤岛?
- How to run dist file on local computer
猜你喜欢
随机推荐
嘉为鲸翼·多云管理平台荣获信通院可信云技术服务最佳实践
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-上
Concise Notes on Integrals - Types of Curve Integrals of the Second Kind
Taosi TDengine 2.6+ optimization parameters
els 方块停在方块上。
快解析结合泛微OA
知识图谱之Cypher语言的使用
MySQL【运算符】
连接mysql报错WARN: Establishing SSL connection without server‘s identity verification is not recommended
Two solutions for Excel xlsx file not supported
快解析结合象过河erp
Unity性能分析 Unity Profile性能分析工具
Apache DolphinScheduler's new generation of distributed workflow task scheduling platform in practice - Part 1
积分专题笔记-与路径无关条件
一个低级错误导致的诡异现象——走近科学能拍三集,(C语言)最简单的数组元素读取,不正确!?
Using IN in MySQL will not go through index analysis and solutions
leetcode 剑指 Offer 10- II. 青蛙跳台阶问题
Kotlin 值类 - value class
水电表预付费系统
MySQL Explain 使用及参数详解