Leetcode-Question-536: Construct Binary Tree from String

原文链接:

https://leetcode.com/problems/construct-binary-tree-from-string/

题目描述:

You need to construct a binary tree from a string consisting of parenthesis and integers.

The whole input represents a binary tree. It contains an integer followed by zero, one or two pairs of parenthesis. The integer represents the root’s value and a pair of parenthesis contains a child binary tree with the same structure.

You always start to construct the left child node of the parent first if it exists.

Example:

Note:

  1. There will only be '('')''-' and '0' ~ '9' in the input string.
  2. An empty tree is represented by "" instead of "()".

解析:

【法1】

Updated 2017.10.17

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注