1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 11:08:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/根据二叉树创建字符串 [construct-string-from-binary-tree].html
2022-03-29 12:43:11 +08:00

37 lines
1002 B
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>你需要采用前序遍历的方式,将一个二叉树转换成一个由括号和整数组成的字符串。</p>
<p>空节点则用一对空括号 &quot;()&quot; 表示。而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong> 二叉树: [1,2,3,4]
1
/ \
2 3
/
4
<strong>输出:</strong> &quot;1(2(4))(3)&quot;
<strong>解释:</strong> 原本将是&ldquo;1(2(4)())(3())&rdquo;
在你省略所有不必要的空括号对之后,
它将是&ldquo;1(2(4))(3)&rdquo;
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong> 二叉树: [1,2,3,null,4]
1
/ \
2 3
\
4
<strong>输出:</strong> &quot;1(2()(4))(3)&quot;
<strong>解释:</strong> 和第一个示例相似,
除了我们不能省略第一个对括号来中断输入和输出之间的一对一映射关系。
</pre>