Leetcode-1013 Pairs of Songs With Total Durations Divisible by 60(总持续时间可被 60 整除的歌曲)

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;
        }
};

 

posted @ 2019-03-17 12:56  Asurudo  阅读(279)  评论(0编辑  收藏  举报