Skip to content

Commit ef62e06

Browse files
committed
Runtime: 4 ms (Top 86.00%) | Memory: 41.7 MB (Top 99.33%)
1 parent 63bac0c commit ef62e06

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
// Runtime: 4 ms (Top 86.00%) | Memory: 41.7 MB (Top 99.33%)
12
class Solution {
23
public int minOperations(String s) {
34
int count0 = 0; // changes required when the string starts from 0
45
int count1 = 0; // changes required when the string starts from 1
5-
6+
67
for(int i = 0; i < s.length(); i++){
7-
8-
// string starts with 1 => all chars at even places should be 1 and that at odd places should be 0
8+
9+
// string starts with 1 => all chars at even places should be 1 and that at odd places should be 0
910
if((i % 2 == 0 && s.charAt(i) == '0') || (i % 2 != 0 && s.charAt(i) == '1'))
1011
count1++;
11-
12-
// string starts with 0 => all chars at even places should be 0 and that at odd places should be 1
12+
13+
// string starts with 0 => all chars at even places should be 0 and that at odd places should be 1
1314
else if((i % 2 == 0 && s.charAt(i) == '1') || (i % 2 != 0 && s.charAt(i) == '0'))
1415
count0++;
1516
}
16-
17-
// return minimum of the two
17+
18+
// return minimum of the two
1819
return Math.min(count0, count1);
1920
}
2021
}
21-

0 commit comments

Comments
 (0)