当前位置:网站首页>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(")");
}
}
边栏推荐
猜你喜欢

涛思 TDengine 2.6+优化参数

延迟队列MQ

EViews 12.0软件安装包下载及安装教程

Matplotlib--绘图标记

九九乘法表

20220728 Use the bluetooth on the computer and the bluetooth module HC-05 of Huicheng Technology to pair the bluetooth serial port transmission

积分专题笔记-曲线面积分三大公式

Version management of public Jar packages

一个近乎完美的 Unity 全平台热更方案

leetcode 剑指 Offer 12. 矩阵中的路径
随机推荐
PyTorch安装及环境配置(Win10)
ESP32 入门篇(一)使用 VS Code 进行开发环境安装
2022 Hangzhou Electric Multi-School 2nd Game
Unity性能分析 Unity Profile性能分析工具
20220728 Use the bluetooth on the computer and the bluetooth module HC-05 of Huicheng Technology to pair the bluetooth serial port transmission
聊聊 MySQL 事务二阶段提交
包、类及四大权限和static
Detailed description of iperf3 parameter options
Integral Special Notes - Definition of Integral
积分简明笔记-第一类曲线积分的类型
Integral Special Notes-Three Formulas for Curve Area Integral
Shell系统学习之数组
Concise Notes on Integrals - Types of Curve Integrals of the First Kind
百度paddleocr检测训练
转行软件测试,报培训班3个月出来就是高薪工作,靠谱吗?
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-上
Test automation selenium (a)
时刻铭记:总有一天你将破蛹而出
2022/07/29 学习笔记 (day19)异常处理
qsort 函数的使用及其模拟实现