Look at my code #take a break & laugh#


  • 1
    F

    Get TLE

    public int bulbSwitch(int n) {
        int onCnt = 0;
        for(int i = 1 ; i <= n; i++) {
            int toggle = 0;
            for(int k = 1; k <= i; k++) {
                if(i % k == 0)
                    toggle ++;
            }
    
            if (toggle % 2 == 1)
                onCnt ++;
        }
        return onCnt;
    }

Log in to reply
 

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