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

牛牛的字符串解码问题

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 »