One line solution in c++..


  • 2
    D

    since only perfect squares have odd number of factors!!

    class Solution {
    public:
        int bulbSwitch(int n)
                {
                     int k=sqrt(n);
                  return k;
        }
    };

Log in to reply
 

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