题目

bulb-switcher


2. 算法

* 直接模拟

* 直接模拟优化


3. 代码

* 直接模拟

class Solution {
public:
    int bulbSwitch(int n) {
        int res = 1;
        while (res * res <= n) ++res;
        return res - 1;
    }
};

* 直接模拟优化

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

results matching ""

    No results matching ""