https://www.bilibili.com/video/BV1vv411a7r5
从答案出发 枚举加效验
class Solution {
public:
int slove(const string& s, int v)
{
int cnt = 0;
for(int i=0;i<s.size();i++,v=1-v)
{
if(s[i]-'0'!=v) cnt++;
}
return cnt;
}
int minOperations(string s) {
int res = INT_MAX;
//目标串 010101.....
res = min(res, slove(s,0));
//目标串是101010....
res = min(res, slove(s,1));
return res;
}
};