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();
}
};
劲蜡鸡腿堡
发布了24 篇原创文章 · 获赞 1 · 访问量 3392
私信
关注
标签:set,int,initial,672,II,str,Bulb,condition,size 来源: https://blog.csdn.net/qq_37654704/article/details/104455725