-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_152996.java
More file actions
49 lines (41 loc) · 1.24 KB
/
_152996.java
File metadata and controls
49 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
class Solution {
public long solution(int[] weights) {
inputMap(weights);
for(int e : weights){
addAnswer(e);
hm.remove(e);
}
return answer;
}
static HashMap<Integer,Long> hm = new HashMap<>();
static long answer = 0;
public void inputMap(int[] arr){
for(int e : arr){
hm.put(e,hm.getOrDefault(e, 0L) + 1L);
}
}
public void addAnswer(int n){
if(hm.containsKey(n)){
long cnt = hm.get(n);
// 동일한 값
if(cnt>1){
for(long k=(long)(cnt-1); k>0; k--){
answer += k;
}
}
answer += cnt * hm.getOrDefault(n*2,0L);
if(n%2==0){
answer += cnt * hm.getOrDefault(n/2,0L);
answer += cnt * hm.getOrDefault(n/2*3,0L);
}
if(n%3==0){
answer += cnt * hm.getOrDefault(n/3*2,0L);
answer += cnt * hm.getOrDefault(n/3*4,0L);
}
if(n%4==0){
answer += cnt * hm.getOrDefault(n/4*3,0L);
}
}
}
}