aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2023-12-24 22:29:57 +0000
committerterminaldweller <devi@terminaldweller.com>2023-12-24 22:29:57 +0000
commit7053dca554a4a7107d809e1ee300562d23ab88b4 (patch)
tree34d19906bcaca40432f434a334067c78808e7dc8
parent1496 (diff)
downloadleetcode-7053dca554a4a7107d809e1ee300562d23ab88b4.tar.gz
leetcode-7053dca554a4a7107d809e1ee300562d23ab88b4.zip
1758
-rwxr-xr-x1758/main.py34
1 files changed, 34 insertions, 0 deletions
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()