题解 | #牛牛的字符串解码问题#

牛牛的字符串解码问题

https://www.nowcoder.com/practice/e5658311e6d44b74872e843ba13ee290

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param s string字符串 
# @return string字符串
#
class Solution:
    def decodeString(self , s: str) -> str:
        # write code here
        
		# replace the origin string to eliminate "["
        while "[" in s:
			# process the last "[" in the current string to deal with [[]]
            for i in range(len(s)-1,0,-1):
                if s[i] == "[":
                    for j in range(i+1,len(s)):
                        if s[j] == "]":
							# replace s by simply adding 
                            s = s[:i-1]+int(s[i-1])*s[i+1:j]+s[j+1:]
                            break
        return s

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务
OSZAR »