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. Google-优秀移动站点设计10招

    Google-优秀移动网站设计10招 1)添加一个醒目的搜索条:在移动终端上,人们希望能够快速找到自己需要的东西 2)把大表格拆分成小块:别搞一个长长的表格页面,上面包含各种输入框 3)允许用户匿名浏 ...

  2. JSON Web Token(JWT)学习笔记

    1.JWT 的Token 标准的Token由三个部分并以.(点号)连接方式组成,即 header.payload.signature,如下 eyJhbGciOiJIUzI1NiIsInR5cCI6Ik ...

  3. mac iterm2

    配置的效果图 : 先讲 iterm2 的配色,再讲 显示分支以及高亮. 一. 配色 打开iterm的官方主题配置站 github.com/mbadolato/iTerm2-Color-Schemes, ...

  4. 【转】Java虚拟机详解----常用JVM配置参数

    原文地址:http://www.cnblogs.com/smyhvae/p/4736162.html 本文主要内容: Trace跟踪参数 堆的分配参数 栈的分配参数 零.在IDE的后台打印GC日志: ...

  5. Spring框架总结(六)

    注解 注解方式可以简化spring的IOC容器的配置! 使用注解步骤: 1)先引入context名称空间 xmlns:context="http://www.springframework. ...

  6. Integer和String "+""=="方法的不同

    在上面的两个篇博客中,我们看到String和Integer不同的常量池的变现形式 我们再看一个例子: public static void main(String[] args) { // TODO ...

  7. 设计模式19:Chain Of Responsibility 职责链模式(行为型模式)

    Chain Of Responsibility 职责链模式(行为型模式) 请求的发送者与接受者 某些对象请求的接受者可能有多种多样,变化无常…… 动机(Motivation) 在软件构建过程中,一个请 ...

  8. CSS 形状绘制

                                      最后一个 先放代码 <style type="text/css"> #heart { positio ...

  9. [LeetCode 题解]: Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  10. ASP.NET MVC ActionFilterAttribute用法