1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class Solution { public int numPairsDivisibleBy60(int[] time) { int pairs = 0;
Map<Integer, Integer> maxDigitNumToMaxNumMap = new HashMap<>(); for (int second : time) { second %= 60; int count = maxDigitNumToMaxNumMap.getOrDefault(second == 0 ? 0 : 60 - second, 0); pairs += count; maxDigitNumToMaxNumMap.put(second, maxDigitNumToMaxNumMap.getOrDefault(second, 0) + 1); }
return pairs; } }
|
References
1010. Pairs of Songs With Total Durations Divisible by 60