leetcode Mini Parser

leetcode Mini Parser

Given a nested list of integers represented as a string, implement a parser to deserialize it.

Each element is either an integer, or a list — whose elements may also be integers or other lists.

Note: You may assume that the string is well-formed:

  • String is non-empty.
  • String does not contain white spaces.
  • String contains only digits 0-9, [, ,, ].

Example 1:

Example 2:

题目地址:leetcode Mini Parser

题意:给定一个字符串,要求把它解析成NestedInteger 类型


第3个A此题 怀疑前两个是出题的人自己测试的= = 本来发了discuss 想想还是只发blog吧~

本题的NestedInteger结构 和341. Flatten Nested List Iterator 类似


接下来,用一个栈来维护,对于左括号[的,当前的NestedInteger 进栈,对于右括号,当前数字放入NestedInteger 栈不为空则把栈顶的NestedInteger添加当前的NestedInteger,并且出栈。





本题是leetcode 385 Mini Parser 的题解


本博客若无特殊说明则由 hrwhisper 原创发布
转载请点名出处:细语呢喃 > leetcode Mini Parser


Leetcode , , . permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *