From 7053dca554a4a7107d809e1ee300562d23ab88b4 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sun, 24 Dec 2023 17:29:57 -0500 Subject: 1758 --- 1758/main.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 1758/main.py (limited to '1758/main.py') diff --git a/1758/main.py b/1758/main.py new file mode 100755 index 0000000..79325e8 --- /dev/null +++ b/1758/main.py @@ -0,0 +1,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() -- cgit v1.2.3