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

Posted Asurudo Jyo の 倉 庫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
        }
};

 

以上是关于Leetcode-1013 Pairs of Songs With Total Durations Divisible by 60(总持续时间可被 60 整除的歌曲)的主要内容,如果未能解决你的问题,请参考以下文章

[Daily Coding Problem 68] Count Pairs of attacking bishop pairs

1512. Number of Good Pairs

[LeetCode] 1512. Number of Good Pairs

Number of Equivalent Domino Pairs

[LeetCode 1530] Number of Good Leaf Nodes Pairs

1128. Number of Equivalent Domino Pairs