题目描述:
一开始想成了用map来实现,但是一想不对劲,奈何只能用笨方法来实现了
代码如下:
class Solution {
public int numPairsDivisibleBy60(int[] time) {
for (int i = 0; i < time.length; i++) {
time[i] = time[i] % 60;
}
int result = 0;
for (int i = 0; i < time.length; i++) {
for (int j = i + 1; j < time.length; j++) {
if((time[i] + time[j]) % 60 == 0){
result ++;
}
}
}
return result;
}
}
再看看别人写的代码
好像也是这个思路
class Solution {
public int numPairsDivisibleBy60(int[] time) {
int count=0;
if(time.length==1){
return count;
}
for(int i=0;i<time.length-1;i++){
for(int j=i+1;j<time.length;j++){
if((time[i]+time[j])%60==0){
count++;
}
}
}
return count;
}
}