LeetCode 319. Bulb Switcher

题目

找规律

const int MAXN = 2e5;
class Solution {
public:
    long long square[MAXN];
    int pos=0;
    int bulbSwitch(int n) {
        
        for(long long i=1;i INT_MAX)
                break;
            square[++pos] = i*i;
        }
        
        int l = 1;
        int r = pos;
        
        while(l<=r)
        {
            int mid = (l+r)/2;
            if(n>square[mid])
            {
                l = mid+1;
            }
            else if(n

你可能感兴趣的:(LeetCode 319. Bulb Switcher)