This is accepted, but...


  • 0
    H
    public int sqrt(int x) {
        return (int)Math.pow(x, 0.5);
    }

  • 0
    M

    So what's the question? Just an observation that that is accepted?


  • 0
    H

    The question is if this should be accepted.


  • 4
    M

    The problem as it is does technically answer the problem quickly, so there is no reason for it not to be accepted. The judge can only determine correct or not, and fast enough or not; it has no way of telling what kind of solution it is.

    This is unlikely to be the accepted answer in an interview, but it would probably get you a couple bonus points for pointing it out. You are much more likely to be asked to do it again without using that function, since this would take very little time to write, and is only one step away from return (int)Math.sqr(x);. It may be accepted regardless, just be prepared to do more as well.


  • 0
    H

    Thank you mike3. So I still have to work on another solution.


  • 1
    K
    public class Solution {
        public int sqrt(int x) {
            return (int)Math.sqrt(x);
        }
    }
    

    Accepted :P :P :P


  • 0
    X

    I think your are lucky to get accepted. When I use C++ to do this:
    class Solution {
    public:
    int sqrt(int x) {
    return (int)sqrt(double(x+0.001));
    }
    };

    What I got is Runtime Error.


  • 0
    W

    depends what you are doing here for...
    just being thrilled to see green fonts of "Accepted"....
    or practice coding skills to find a job...


Log in to reply
 

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