Decode String
Given an expressions
includes numbers, letters and brackets. Number represents the number of repetitions inside the brackets(can be a string or another expression).Please expand expression to be a string.
Example
s =abc3[a]
returnabcaaa
s =3[abc]
returnabcabcabc
s =4[ac]dy
, returnacacacacdy
s =3[2[ad]3[pf]]xyz
, returnadadpfpfpfadadpfpfpfadadpfpfpfxyz
Note
两个栈,一个存数字,一个存String
遇到数字,读取数字
遇到字符,读取字符串
遇到 “ [ ”,压入数字入栈,count归0,压入字符串入栈,字符串归空
遇到 “ ] ",数字出栈,字符串出栈,重复数字次,即为新的字符串
Code
Last updated