Does OJ support eval?

  • 0

    Out of pure laziness, I attempted this solution to the problem:

    class Solution:
        # @param num1, a string
        # @param num2, a string
        # @return a string
        def multiply(self, num1, num2):
            return str(eval(num1 + "*" + num2))

    It works perfectly fine if I run it on my computer, but OJ gives a Compile Error. Does this mean that OJ does not allow the use of eval / exec?

  • 1

    No, we don't support that.

    LeetCode aims to prepare for interview right now. Solution for this problem like yours will never be accepted by interviewee.

Log in to reply

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