class Solution { public: int numPairsDivisibleBy60(vector<int>& time) { int hash[1501] {0}; for(int i = 0;i < time.size();i ++) { hash[time[i]] ++; } int rnt = 0; for(int i = 1;i < 501;i ++) { int left = 60-i; while(left<0) left += 60; while(left>=0&&left <= 1500) { if(left==i) { rnt += (hash[i]*(hash[i]-1))/2; left += 60; continue; } rnt += hash[i]*hash[left]; left += 60; } hash[i] = 0; } return rnt; } };
原文地址:https://www.cnblogs.com/Asurudo/p/10546541.html
时间: 2024-10-08 16:39:17