Is it a kind of cheat trick in Python?


  • 1
    M
    class Solution:
    # @param x, a float
    # @param n, a integer
    # @return a float
    def pow(self, x, n):
        return x**n
    

    this is my code, absloutely accepted.
    So I think in some particular case, some operator or built-in func should be forbidden.


  • 7
    M

    You are right that it is a cheat, but this is similar to the use of "next_permutation" in C++ for the "List all the permutations" problem. I'll answer here what was answered there.

    The point of this site is not just to solve the problem, it's to solve it in a way that would be acceptable in an interview. Answering in a way like you did proves you know the language, and can take advantage of it, but that would only take seconds. Your interviewer would then ask how you'd do it without that operator, and so do we.

    The answer isn't technically wrong, but it isn't really correct either. The next step to this problem is solve it without using features of the language to make it trivial.


  • 2
    S

    Yes, it should be. But unfortunately it does work right now. So it is better to get rid of tricky way by yourself.


Log in to reply
 

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