Created
June 6, 2024 09:57
-
-
Save samarthsewlani/51556d7f018c13fa84fcbeb9ed776d03 to your computer and use it in GitHub Desktop.
Pairs of Songs With Total Durations Divisible by 60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/ | |
class Solution { | |
public int numPairsDivisibleBy60(int[] time) { | |
int n = time.length, count = 0; | |
for(int i=0;i<n;i++) time[i] %= 60; | |
Map<Integer, Integer> visited = new HashMap<>(); | |
for(int i=0;i<n;i++){ | |
int value = (60-time[i])%60; | |
if(visited.containsKey(value)){ | |
count += visited.get(value); | |
} | |
visited.put(time[i], visited.getOrDefault(time[i], 0) + 1); | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment