当前位置:网站首页>606. 根据二叉树创建字符串(视频讲解!!!)
606. 根据二叉树创建字符串(视频讲解!!!)
2022-07-30 09:15:00 【学习追求高效率】
13. (有视频)前序遍历二叉树 转成 字符串
前序遍历二叉树转成字符串
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(")");
}
}
边栏推荐
猜你喜欢
随机推荐
最长公共序列、串问题总结
经历了这样一个阶段的发展之后,数字零售才能有新的进化
Integral Special Notes-Three Formulas for Curve Area Integral
实战演练 | 在 MySQL 中计算每日平均日期或时间间隔
Reflection tricks can boost your performance by N times
LeetCode二叉树系列——94.二叉树的中序遍历
转行软件测试,报培训班3个月出来就是高薪工作,靠谱吗?
百度paddleocr检测训练
积分简明笔记-第一类曲线积分的类型
企业数字化建设,自研还是采购?
PyQt5-绘制不同类型的直线
342 · 山谷序列
【 HMS core 】 【 】 the FAQ HMS Toolkit collection of typical questions 1
方法的参数传递
Integral Special Notes - Definition of Integral
Unity performance analysis Unity Profile performance analysis tool
[Yugong Series] July 2022 Go Teaching Course 021-Slicing Operation of Go Containers
MySQL中使用IN 不会走索引分析以及解决办法
02-课程发布
PyQt5快速开发与实战 8.1 窗口风格









