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. python准确判断文件类型

    判断文件类型在开发中非常常见的需求,怎样才能准确的判断文件类型呢?首先大家想到的是文件的后缀,但是非常遗憾的是这种方法是非常不靠谱的,因为文件的后缀是可以随意更改的,而大家都知道后缀在linux系统下 ...

  2. oracle11g客户端配置及使用(Instant Client)

      http://www.oracle.com/technetwork/topics/winx64soft-089540.html http://www.cnblogs.com/ychellboy/a ...

  3. 'for each' statements are only available if source level is 5.0

    在用foreach的时候,出现以下错误: 错误:Syntax error, 'for each' statements are only available if source level is 5. ...

  4. Halcon标定与自标定

    Halcon标定:https://blog.csdn.net/niyintang/article/details/78752585 Halcon自标定:https://www.cnblogs.com/ ...

  5. .NET基础 (05)内存管理和垃圾回收

    内存管理和垃圾回收1 简述.NET中堆栈和堆的特点和差异2 执行string abc="aaa"+"bbb"+"ccc"共分配了多少内存3 ...

  6. web_custom_request函数详解【摘抄】

    本次摘抄自:http://www.cnblogs.com/yezhaohui/p/3280239.html web_custom_request()函数是一个可以用于自定义http请求的“万能”函数, ...

  7. Linux中VMware虚拟机增加磁盘空间的扩容操作

    用VMwareware虚拟机安装的Red Hat Enterprise Linux系统剩余空间不足,造成软件无法正常安装.如果重新装一遍系统就需要重新配置好开发环境和软件的安装配置.通过上网搜集的资料 ...

  8. SSH密钥登陆

    参考: SSH公钥登录原理 比如git可以生成公钥,然后用有权限的账户把他加到仓库上,以后就可以通过公钥登陆了.不需要像https那样需要有账号,但是权限管理就不细了. 有时候如果仓库上添加了多个公钥 ...

  9. C#操作Json数据

    JSON是现今各语言实现数据交互应用最广泛的一种格式,在于Xml的比较中,由于 JSON 所使用的字符要比 XML 少得多,可以大大得节约传输数据所占用得带宽. 本文采用的是Newtonsoft.Js ...

  10. Django 标签过滤器

    django内置标签 autoescape 控制当前的自动转义行为.这个标记可以作为参数打开或关闭,它决定自动转义是否在块内有效.块使用endautoescape结束标记关闭. 当自动转义生效时,所有 ...