128th LeetCode Weekly Contest 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.
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 <= time.length <= 600001 <= 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的更多相关文章
- 【LeetCode】1013. Pairs of Songs With Total Durations Divisible by 60 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【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 ...
- [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 ...
- 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 ...
- 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/ 参考 ...
- 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 ...
- 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 ...
- LeetCode Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
随机推荐
- tp5 select回显
<select name="role_id" id="" class="form-control" required> {vol ...
- mysql varchar 类型 超出字符
4.0版本以下,varchar(50),指的是50字节,如果存放UTF8汉字时,只能存16个(每个汉字3字节) 5.0版本以上,varchar(50),指的是50字符,无论存放的是数字.字母还是UTF ...
- SDN网络工具
TcpDump 根据使用者的定义对网络上的数据包进行截获的包分析工具. http://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html ...
- springboot启动正常,访问restController报404
原因:spring boot只会扫描启动类当前包和以下的包 比如以下: 主类:Application放在包com.springboot.main controller类放在包com.springboo ...
- /var/run/yum.pid被锁定
当执行yum update时出现: /var/run/yum.pid已被锁定,PID为1610的另一个程序正在运行. 另外一个程序锁定了yum:等待它退出...... 解决办法 rm -f /var/ ...
- 解决Emoji存储MySQL报错问题
在解决之前,得先说明一下为什么会出现报错,Emoji表情占用4个字节,但是MySQL数据库UTF-8编码最多只能存储3个字节,就会导致存储不进去 如何解决Emoji存储问题 mysql 的 utf8编 ...
- 编写高质量代码改善C#程序的157个建议——建议90:不要为抽象类提供公开的构造方法
建议90:不要为抽象类提供公开的构造方法 首先,抽象类可以有构造方法.即使没有为抽象类指定构造方法,编译器也会为我们生成一个默认的protected的构造方法.下面是一个标准的最简单的抽象类: abs ...
- maven3的安装
先来简单介绍一下maven,Maven是Apache的顶级项目,是基于项目对象模型,也就是POM模型,用作项目管理,基本上是用做Java的项目. 1.安装环境准备,首先确定机子上已经安装和配置好了JD ...
- [QPlugins]学习大纲
QPlugins是一个DELPHI实现的插件框架,官方网址是:http://www.qdac.cc/ . 把学习QPlugins的过程和心得做一个记录,以便应用到项目中,同时学习一些实现方法和思想. ...
- How to:Aborting a long running task in TPL
http://social.msdn.microsoft.com/Forums/vstudio/en-US/d0bcb415-fb1e-42e4-90f8-c43a088537fb/aborting- ...