Skip to content

Files

Latest commit

7a7d3f2 · Oct 20, 2020

History

History

0536.Construct Binary Tree from String

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 20, 2020
Oct 20, 2020

English Version

题目描述

你需要从一个包括括号和整数的字符串构建一棵二叉树。

输入的字符串代表一棵二叉树。它包括整数和随后的 0 ,1 或 2 对括号。整数代表根的值,一对括号内表示同样结构的子树。

若存在左子结点,则从左子结点开始构建。

 

示例:

输入:"4(2(3)(1))(6(5))"
输出:返回代表下列二叉树的根节点:

       4
     /   \
    2     6
   / \   / 
  3   1 5   

 

提示:

  • 输入字符串中只包含 '(', ')', '-' 和 '0' ~ '9' 
  • 空树由 "" 而非"()"表示。

 

解法

Python3

Java

...