diff options
-rw-r--r-- | 3.py | 12 |
1 files changed, 3 insertions, 9 deletions
@@ -1,15 +1,9 @@ -from collections.abc import Iterable - Bits = tuple[bool, ...] Input = list[Bits] -def most_common(nums: Iterable[Bits], n: int) -> bool: - count: int = 0 - length: int = 0 - for num in nums: - if num[n]: count += 1 - length += 1 - return count >= length - count +def most_common(nums: list[Bits], n: int) -> bool: + count = sum(num[n] for num in nums) + return count >= len(nums) - count def bits_to_int(bits: Bits) -> int: return sum(b * 2 ** i for i, b in enumerate(reversed(bits))) |