Pairs of Songs With Total Durations Divisible by 60 (Leetcode 1010)
Problem Link: https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/
class Solution:
def numPairsDivisibleBy60(self, time: List[int]) -> int:
d={}
n=len(time)
ans=0
for i in range(n):
rem=time[i]%60
if(rem==0):
if(0 in d):
ans=ans+d[0]
else:
if(60-rem in d):
ans=ans+d[60-rem]
if(rem not in d):
d[rem]=1
else:
d[rem]+=1
return ans
Last updated