Skip to content

Commit eb856df

Browse files
authored
Create Minimum Changes To Make Alternating Binary String.cpp
1 parent 18e0529 commit eb856df

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public:
3+
int minOperations(string s) {
4+
int zero=0;
5+
int one=0;
6+
for(int i=0;i<s.size();++i) {
7+
if(i%2==0)
8+
{
9+
zero+=(s[i]=='1');
10+
}
11+
else
12+
{
13+
zero+=(s[i]=='0');
14+
}
15+
if(i%2==0)
16+
{
17+
one+=(s[i]=='0');
18+
}
19+
else
20+
{
21+
one+=(s[i]=='1');
22+
}
23+
}
24+
return min(zero,one);
25+
}
26+
};

0 commit comments

Comments
 (0)