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.

Example 1:

Input: [30,20,150,100,40]
Output: 3
Explanation: Three pairs have a total duration divisible by 60:
(time[0] = 30, time[2] = 150): total duration 180
(time[1] = 20, time[3] = 100): total duration 120
(time[1] = 20, time[4] = 40): total duration 60

Example 2:

Input: [60,60,60]
Output: 3
Explanation: All three pairs have a total duration of 120, which is divisible by 60.

Note:

  1. 1 <= time.length <= 60000
  2. 1 <= time[i] <= 500

本来是个很简单的题目,不小心我给写复杂了。

但这样就很好理解了。我们找的就是余数也是i和60-i这种,然后考虑排列组合就好了。注意0和30这种组合。

简单的代码依然可以看大佬的

class Solution {
public:
int numPairsDivisibleBy60(vector<int>& time) {
int count[] = {};
int len = time.size();
for(int i = ; i < len ; i++){
int x = time[i] % ;
count[x]++;
}
int i;
int result = count[] * (count[] - ) / ;
for(i = ;i < ( + ) / ; ++ i){
result += count[i] * count[ - i];
}
if( * i == ){
result += count[i] * (count[i] - ) / ;
}
return result;
}
};

128th LeetCode Weekly Contest Pairs of Songs With Total Durations Divisible by 60的更多相关文章

  1. 【LeetCode】1013. Pairs of Songs With Total Durations Divisible by 60 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. 【leetcode】1013. 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 pair ...

  3. [Swift]LeetCode1010. 总持续时间可被 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 s ...

  4. 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 s ...

  5. 1013. Pairs of Songs With Total Durations Divisible by 60总持续时间可被 60 整除的歌曲

    网址:https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/submissions/ 参考 ...

  6. 128th LeetCode Weekly Contest Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  7. 128th LeetCode Weekly Contest Complement of Base 10 Integer

    Every non-negative integer N has a binary representation.  For example, 5 can be represented as &quo ...

  8. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  9. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

随机推荐

  1. 最小生成树 prim

    1.算法思想: 图采用邻接矩阵存储,贪心找到目前情况下能连上的权值最小的边的另一端点,加入之,直到所有的顶点加入完毕. 2.算法实现步骤: 设图G =(V,E),其生成树的顶点集合为U. (1)把v0 ...

  2. [Training Video - 3] [Groovy in Detail] What is a groovy class ?

    log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() ...

  3. Ha-Federation-hdfs +Yarn集群部署方式

    经过一下午的尝试,终于把这个集群的搭建好了,搭完感觉也没有太大的必要,就当是学习了吧,为之后搭建真实环境做基础. 以下搭建的是一个Ha-Federation-hdfs+Yarn的集群部署. 首先讲一下 ...

  4. ServiceStack.Redis.RedisNativeClient的方法“get_Db”没有实现。

    项目中用到redis,用nuget导入,但是运行时遇到问题 Exception: “Com.JinYiWei.Cache.RedisHelper”的类型初始值设定项引发异常.System.TypeIn ...

  5. asp.net WebAPI 问题 iisnode默认不支持PUT和DELETE的解决

    因为iisnode的自动重启服务器方便,一直用的它来作为开发中的node服务器,今天一个delete命令过去,得到一个405(?好像是)错误,让我很郁闷. 用原生的node试一下,是完美支持的,本来打 ...

  6. CodeForces 907E Party(bfs+状压DP)

    Arseny likes to organize parties and invite people to it. However, not only friends come to his part ...

  7. 走进AOP In .NET

    AOP是什么,有的译为面向方面编程,有的译为面向切面编程,我更加赞同后者.接下来,让我们一步步揭开AOP的面纱. AOP衍生自 编程中出现了一些用OOP技术无法捕捉和解决的问题.跟其他开发工具和思想一 ...

  8. ZKEACMS 如何使用组件自定义样式/编辑样式

    前言 如果你还不知道ZKEACMS,不妨先了解一下. ASP.NET MVC 开源建站系统 ZKEACMS 推荐,从此网站“拼”起来 官方地址:http://www.zkea.net/zkeacms ...

  9. Qt学习(二):项目学习

    1. 概述 Qt做UI设计后,通常会生成Form Files文件夹下的ui文件.Generated File文件夹下的ui_xxx等头文件和源文件.Header Files文件夹下的头文件.Sourc ...

  10. sharepoint用户信息同步出错

    首先使用工具定位问题,然后权限不够授予权限 C:\Program Files\Microsoft Office Servers\15.0\Synchronization Service\UIShell