Skip to content

Commit ca4d5f0

Browse files
Create 1758-minimum-changes-to-make-alternating-binary-string.java
1 parent 3e2054d commit ca4d5f0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int minOperations(String s) {
3+
int count = 0;
4+
5+
for(int i = 0; i < s.length(); i++){
6+
if(i % 2 == 1)
7+
count += (s.charAt(i) == '0')? 1: 0;
8+
else
9+
count += (s.charAt(i) == '1')? 1: 0;
10+
}
11+
return Math.min(count, s.length() - count);
12+
}
13+
}

0 commit comments

Comments
 (0)