aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-01-04 02:06:17 +0000
committerterminaldweller <devi@terminaldweller.com>2024-01-04 02:06:17 +0000
commit0523c6357392a43ac0842465cd20090e53f3b52e (patch)
tree019dbd3312621f8287b7032d078faa5063b179a5
parent2635 (diff)
downloadleetcode-0523c6357392a43ac0842465cd20090e53f3b52e.tar.gz
leetcode-0523c6357392a43ac0842465cd20090e53f3b52e.zip
2870
-rwxr-xr-x2870/main.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/2870/main.py b/2870/main.py
new file mode 100755
index 0000000..6534c78
--- /dev/null
+++ b/2870/main.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+import typing
+
+
+class Solution:
+ def minOperations(self, nums: typing.List[int]) -> int:
+ dicts: typing.Dict = {}
+ for num in nums:
+ if num in dicts:
+ dicts[num] += 1
+ else:
+ dicts[num] = 1
+
+ sum = 0
+ print(dicts)
+ for k, v in dicts.items():
+ if v == 1:
+ return -1
+ sum += v // 3
+ if v % 3:
+ sum += 1
+
+ return sum
+
+
+def main():
+ solution = Solution()
+ print(solution.minOperations([2, 3, 3, 2, 2, 4, 2, 3, 4]))
+ print(solution.minOperations([2, 1, 2, 2, 3, 3]))
+ print(
+ solution.minOperations(
+ [14, 12, 14, 14, 12, 14, 14, 12, 12, 12, 12, 14, 14, 12, 14, 14, 14, 12, 12]
+ )
+ )
+ print(solution.minOperations([19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19]))
+
+
+if __name__ == "__main__":
+ main()