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

原文地址:https://www.cnblogs.com/Asurudo/p/10546541.html

时间: 2024-08-04 05:50:30

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

1013. Pairs of Songs With Total Durations Divisible by 60

time >=1 and <= 500, so sum >= 2 and sum <= 1000 there are 16 numbers in this interval divisible by 60 from 60 to 960, so the problem becomes find the number of pairs with sum of 60...960 class Solution { public int numPairsDivisibleBy60(int[]

[Swift Weekly Contest 128]LeetCode1013. 总持续时间可被 60 整除的歌曲 | Pairs of Songs With Total Durations Divisible by 60

In a list of songs, the i-th song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60.  Formally, we want the number of indices i < j with (time[i] + time[j]) % 60 == 0.

Pairs of Songs With Total Durations Divisible by 60 LT1010

In a list of songs, the i-th song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60.  Formally, we want the number of indices i < j with (time[i] + time[j]) % 60 == 0.

力扣(LeetCode) 1010. 总持续时间可被 60 整除的歌曲

在歌曲列表中,第 i 首歌曲的持续时间为 time[i] 秒. 返回其总持续时间(以秒为单位)可被 60 整除的歌曲对的数量.形式上,我们希望索引的数字 i < j 且有 (time[i] + time[j]) % 60 == 0. 示例 1: 输入:[30,20,150,100,40] 输出:3 解释:这三对的总持续时间可被 60 整数: (time[0] = 30, time[2] = 150): 总持续时间 180 (time[1] = 20, time[3] = 100): 总持续时间

LeetCode -Reverse Pairs

my solution: class Solution { public: int reversePairs(vector<int>& nums) { int length=nums.size(); int count=0; for (int i=0;i<length;i++) { for(int j=i+1;j<length;j++) { if(nums[i]>2*nums[j]) count++; } } return count; } }; wrong answ

LeetCode K-diff Pairs in an Array

原题链接在这里:https://leetcode.com/problems/k-diff-pairs-in-an-array/#/description 题目: Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), wh

[LeetCode]Palindrome Pairs

题目:Palindrome Pairs Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. Example 1:Given words = ["bat", "tab",

[LeetCode] Reverse Pairs 翻转对

Given an array nums, we call (i, j) an important reverse pair if i < j and nums[i] > 2*nums[j]. You need to return the number of important reverse pairs in the given array. Example1: Input: [1,3,2,3,1] Output: 2 Example2: Input: [2,4,3,5,1] Output:

[LeetCode] Palindrome Pairs 回文对

Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. Example 1:Given words = ["bat", "tab", "cat"]Ret