Pairs of Songs With Total Durations Divisible by 60

给一个数组, 找到其中有多少对数的和整除60。这里上来先取模,然后就是2sum pair

class Solution {
    public int numPairsDivisibleBy60(int[] time) {
        for(int i = 0 ; i < time.length; i++) {
            time[i] %= 60;
        }
        int count = 0;
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for(int i = 0; i < time.length; i++) {
            int key = (60 - time[i]) % 60;
            count += map.getOrDefault(key, 0);
            map.put(time[i], map.getOrDefault(time[i], 0)+1);
        }
        return count;
    }
}