blob: 79325e8a2240675643b5ebc0fa567422b31c3f5e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/usr/bin/env python
class Solution:
def minOperations(self, s: str) -> int:
f_c = 0
b_c = 0
cond = 48
for c in s:
if ord(c) != cond:
f_c += 1
if cond == 48:
cond = 49
else:
cond = 48
if ord(c) != cond:
b_c += 1
print(f_c, b_c)
return min(f_c, b_c)
def main():
solution = Solution()
print(solution.minOperations("0100"))
print(solution.minOperations("10"))
print(solution.minOperations("1111"))
print(solution.minOperations("1100010111"))
if __name__ == "__main__":
main()
|