c++ | easy | short
\n# Code\n\nclass Solution {\npublic:\n   int minFlips(string s) {\n        int n=s.size();\n        vector<vector<int> > cnt(2, vector<int>(2, 0));\n        \n
\n# Code\n```\nclass Solution {\npublic:\n   int minFlips(string s) {\n        int n=s.size();\n        vector<vector<int> > cnt(2, vector<int>(2, 0));\n        \n        for(int i=0; i<n; i++){\n            cnt[s[i]-\'0\'][i%2]++;\n        }\n        int ans=cnt[1][0]+cnt[0][1]; \n        ans=min(ans, cnt[0][0]+cnt[1][1]); \n        for(int i=0; i<n; i++){\n            cnt[s[i]-\'0\'][i%2]--;\n            cnt[s[i]-\'0\'][(n+i)%2]++;\n            ans=min(ans, cnt[1][0]+cnt[0][1]);\n            ans=min(ans, cnt[0][0]+cnt[1][1]);\n        }\n        return ans;\n    }\n\n};\n```
['C++']