长春建站公众号,免费网站建设apk,建设网站可以赚钱吗,网站建设思维导图模板思路#xff1a;类似于入栈出栈的操作#xff0c;分层保存数字和字符串#xff0c;然后逐层相乘合并#xff0c;通过判断当前字符和上一个字符类型来确定数字是否结束
class Solution:def decodeString(self, s: str) - str:current_str []current_num[]…
思路类似于入栈出栈的操作分层保存数字和字符串然后逐层相乘合并通过判断当前字符和上一个字符类型来确定数字是否结束
class Solution:def decodeString(self, s: str) - str:current_str []current_num[]last_charfor each_char in s:if each_char.isalpha():current_str[-1] each_charelif each_char.isnumeric():if not last_char.isnumeric():current_num.append(0)current_num[-1] current_num[-1] * 10 int(each_char)elif each_char [:current_str.append()elif each_char ]:current_str[-2] current_str[-1] * current_num[-1]current_str.pop(-1)current_num.pop(-1)last_chareach_charwhile current_num:print(current_str, current_num)current_str[-2]current_str[-1]*current_num[-1]current_str.pop(-1)current_num.pop(-1)print(current,current_str)return current_str[-1]