0 ms no additional library functions


  • 0
    1

    There are a ton of sqrt functions. I just wanted to post bottom up C solution.

    Considering its a 32bit integer input, maximum run time would be a 65,535 iteration.

    int bulbSwitch(int n) {
        int i =1, res=0;
        if(!n) return 0;
        while((i*i) <= n) {
             res+=1;i+=1;
        }
        return res;
    }

  • 1
    S

    int bulbSwitch(int n)
    {
    return sqrt(n);
    }


Log in to reply
 

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