Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char flip(char ch) {
- return ( ch == '0') ? '1' : '0';
- }
- int minFlips(string str, char expected) {
- int count = 0;
- for (int i=0; i<str.length(); i++) {
- if (str[i] != expected) {
- count ++;
- }
- expected = flip(expected);
- }
- return count;
- }
- int minFlips (string S)
- {
- return min(minFlips(S, '1'), minFlips(S, '0'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement