Minimum Suffix Flips LeetCode solution in C++

1
class Solution {
2
public:
3
int minFlips(string target) {
4
int count = 0;
5
// we see thye number of times the change occur
6
for (int i = 0; i < target.size() - 1; i++) {
7
if (target[i] != target[i + 1]) {
8
count++;
9
}
10
}
11
if (target[0] == '0') {
12
return count;
13
} else {
14
return count + 1;
15
}
16
return 0;
17
}
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0