class Solution(object):
    def rle_decoding(self, strs):
        res_list, cnt_list, res_str, cnt, i = [], [], '', 0, 0
        while i < len(strs):
            if strs[i].isdigit():
                cnt=cnt*10+int(strs[i])
                i += 1
                continue
            else:
                j = i
                while j < len(strs) and not strs[j].isdigit():
                    j += 1
                res_list.append(strs[i:j])
                cnt_list.append(cnt)
                cnt = 0
                i = j
        for k in xrange(len(res_list)):
            res_str += res_list[k] * cnt_list[k]
        return res_str

    def decodeString(self, strs):
        """
        :type s: str
        :rtype: str
        """
        stck = []
        for i in xrange(len(strs)):
            if strs[i] == ']':
                tstr = []
                while stck and stck[-1] != '[':
                    tstr.insert(0,stck.pop())
                if stck:
                    # pop out the '['
                    stck.pop()
                    # add the number
                    while stck and stck[-1].isdigit():
                        tstr.insert(0,stck.pop())
                    # add to result
                    stck.append(self.rle_decoding(''.join(tstr)))
            else:
                stck.append(strs[i])
        return ''.join(stck) if stck else ''
        
@@ -633,16 +633,587 @@
 res_str%0A
+    def decodestr(self,strs):%0A        cnt,res=%5B%5D,%5B%22%22%5D%0A        i=0%0A        while i%3Clen(strs):%0A            if strs%5Bi%5D.isdigit():%0A                start=i%0A                while strs%5Bi+1%5D.isdigit():%0A                    i+=1%0A                cnt.append(int(strs%5Bstart:i+1%5D))%0A            elif strs%5Bi%5D=='%5B':%0A                res.append(%22%22)%0A            elif strs%5Bi%5D=='%5D':%0A                substr=res.pop()*cnt.pop()%0A                res.append(res.pop()+substr)%0A            else:%0A                res.append(res.pop()+strs%5Bi%5D)%0A            i+=1%0A        return res.pop()%0A                
 %0A    def
@@ -1296,32 +1296,77 @@
 str%0A        %22%22%22%0A
+        return self.decodestr(strs)%0A        %0A
         stck = %5B

[394. Decode String][Accepted]committed by Victor