672. Bulb Switcher II

问题传送门

问题分析

TODOing

完整代码


class Solution {
public:
    void function(string &str, int begin, int step){
        for(int i = begin; i < str.size(); i+=step){
            if(str[i] == '1')
                str[i] = '0';
            else
                str[i] = '1';
        }
    }
    int flipLights(int n, int m) {
        string initial;
        for(int i = 0; i < n; i++)
            initial += '1';
        unordered_set<string> set;

        vector<vector<vector<int>>> sequ = {{{0, 0, 0, 0}},
                                           {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}},
                                           {{1, 1, 0, 0}, {1, 0, 1, 0}, {1, 0, 0, 1}, {0, 1, 1, 0}, {0, 1, 0, 1}, {0, 0, 1, 1}},
                                           {{0, 1, 1, 1}, {1, 0, 1, 1}, {1, 1, 0, 1}, {1, 1, 1, 0}},
                                           {{1, 1, 1, 1}}};
        vector<vector<int>> ope = {{0, 1}, {1, 2}, {0, 2}, {0, 3}};    
        vector<vector<int>> condition = {{0, 0}, {1, 1}, {0, 2}, {1, 3}, {0, 4}};    
        for(int i = 0; i < condition.size(); i++){
            if(m % 2 == condition[i][0] && m >= condition[i][1]){
                for(auto &se: sequ[i]){
                    string effectStr = initial;
                    for(int i = 0; i < se.size(); i++){
                        if(se[i] == 1)
                            function(effectStr, ope[i][0], ope[i][1]);
                    }
                    set.insert(effectStr);
                }
            }
        }
        return set.size();
    }
};
672. Bulb Switcher II672. Bulb Switcher II 劲蜡鸡腿堡 发布了24 篇原创文章 · 获赞 1 · 访问量 3392 私信 关注
上一篇:JUC-Condition线程通信


下一篇:关于AQS的理解