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:
解法1: Stack O(N)
用一个stack来存储每一个当前的nestedInteger。
用一个variable存储指针使得他指向当前要parse的数字的开始位置。
每次看到一个,或者是]的时候就表示当前的nestedInteger结束了,所以需要把当前的数字放入nestedInteger。如果是],如果当前的stack不为空,那么就说明这个integer属于另一个integer
|
|