Why does python eval doesn't work in the OJ?


  • 0
    X

    I was trying to use Python eval function to directly construct the list, it seems to work on my local computer but not in the OJ. Any ideas why that happens?

    class Solution(object):
        def decodeString(self, s):
            s1 = "["       
            for c in s:
                if c.isnumeric():
                    s1 += '*' + c + '*'
                elif c.isalpha():
                    s1 += "'"+ c + "',"
                elif c == ']':
                  s1 += c + ','
                else:
                    s1 += c
            s1 += ']'
            print(s1)
            ls = eval(s1)
            return "".join(ls)        
    

    For example,decodeString("3[a2[c]]") works on my local computer but not in the OJ.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.