![]() Formally, we want the number of indices i, j such that i < j. You are given a list of songs where the ith song has a duration of timei seconds. In a list of songs, thei-thsong has a duration oftimeiseconds.Return the number of pairs of. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Pairs of Songs With Total Durations Divisible by 60. We should notice that 1 int: from collections import Counter total = 0 counts = Counter() if 30 in counts: total += counts * (counts - 1) / 2 del counts if 0 in counts: total += counts * (counts - 1) / 2 del counts for i in range(1, 30): if i in counts and (60-1) in counts: total += counts * counts return int(total)Īnd this solution is not just only fast, but also memory efficient. Pairs of Songs With Total Durations Divisible by 60. Oops, I get the Time Limit Exceeded error. CSbasics/pairs-of-songs-with-total-durations-divisible-by-60.py at master yennanliu/CSbasics GitHub My CS learning : algorithm, data structure, and system design SE - CSbasics/pairs-of-songs-with-total-durations-divisible-by-60. Formally, we want the number of indices i int: total = 0 for i, song1 in enumerate(time): for j in range(i+1, len(time)): if (song1 + time) % 60 = 0: total += 1 return total Return the number of pairs of songs for which their total duration in seconds is divisible by 60. In a list of songs, the i-th song has a duration of time seconds. Memory Usage: 15.6 MB, less than 100.00% of Python3 submissions Runtime: 60 ms, faster than 99.70% of Python3 submissions ![]() If mod0 or 30, use Cn2 to get the number of possible combinations to form a pair from all songs, else record the count of length k, and the count of length 60-k to get the product of these two counts to get the possible combinations with these two lengths (lengthArr32 & lengthArr573, so there are total of. Longest Substring Without Repeating Characters 4. LeetCode: Binary Gap LeetCode: Binary Prefix Divisible By 5 LeetCode: Pairs of Songs With Total Durations Divisible by 60 LeetCode: X of a Kind in a. Traverse the first half of lengthArr to check the count of each length modulo. Pairs of Songs With Total Durations Divisible by 60 Pairs of Songs With Total Durations Divisible by 60 by Xu LIANG LeetCode Cracker Medium Write Sign up Sign In 500 Apologies, but something went wrong on our end. Pairs of Songs With Total Durations Divisible by 60 - LeetCode Solutions LeetCode Solutions Home Preface Style Guide Problems Problems 1.
0 Comments
Leave a Reply. |