Skip to content

Commit 7b018d0

Browse files
authored
Added Minimum Changes To Make Alternating Binary String.java
1 parent be90aec commit 7b018d0

File tree

1 file changed

+11
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)