LeetCode - 1010. Pairs of Songs With Total Durations Divisible by 60 | Hash Table | Python | Java

Поділитися
Вставка
  • Опубліковано 25 жов 2024

КОМЕНТАРІ • 1

  • @ElFox
    @ElFox 5 місяців тому +1

    Here is one more ineresting solution:
    class Solution:
    # Time Complexity: O(n)
    # Space Complexity: O(1)
    def numPairsDivisibleBy60(self, time: List[int]) -> int:
    remainder_counts = [0] * 60
    count = 0
    for t in time:
    remainder = t % 60
    if remainder == 0:
    count += remainder_counts[0]
    else:
    count += remainder_counts[60 - remainder]
    remainder_counts[remainder] += 1
    return count