Skip to content

Latest commit

 

History

History
55 lines (38 loc) · 1.25 KB

_3185. Count Pairs That Form a Complete Day II.md

File metadata and controls

55 lines (38 loc) · 1.25 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Completed during Weekly Contest 402 (q2)

Back to top


First completed : July 07, 2024

Last updated : July 07, 2024


Related Topics : Array, Hash Table, Counting

Acceptance Rate : 42.99 %


Solutions

Python

class Solution:
    def countCompleteDayPairs(self, hours: List[int]) -> int:
        cnt = Counter([x % 24 for x in hours])

        '''
        0
        1 23
        2 22
        3 21
        ...
        10 14
        11 13
        12
        '''

        vals = []
        vals.append(cnt.get(0, 0) * (cnt.get(0, 0) - 1) // 2)
        vals.append(cnt.get(12, 0) * (cnt.get(12, 0) - 1) // 2)

        for x in range(1, 12) : # [1, 11]
            vals.append(cnt.get(x, 0) * cnt.get(24 - x, 0))


        return sum(vals)