1 line very easy cpp solution


  • 0
    Z

    if the bulb is on at end, then the number of this bulb must have odd factors. and only square number has odd fctors, so we only need to find the number of square number less than n;

    then we only need 1 line and it is prtty easy

    class Solution {
    public:
     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.