-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path가장 많이 받은 선물.java
More file actions
52 lines (41 loc) · 1.34 KB
/
가장 많이 받은 선물.java
File metadata and controls
52 lines (41 loc) · 1.34 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
50
51
52
import java.util.*;
import java.io.*;
class Solution {
public int solution(String[] friends, String[] gifts) {
int n = friends.length;
Map<String, Integer> map = new HashMap<>();
int[][] arr = new int[n][n];
for (int i = 0; i < n; i++) {
map.put(friends[i], i);
}
int a, b;
for (int i = 0;i < gifts.length; i++) {
a = map.get(gifts[i].split(" ")[0]);
b = map.get(gifts[i].split(" ")[1]);
arr[a][b]++;
}
int[] point = new int[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
point[i] += arr[i][j];
point[j] -= arr[i][j];
}
}
int[] res = new int[n];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i][j] > arr[j][i]) res[i]++;
else if (arr[i][j] < arr[j][i]) res[j]++;
else {
if (point[i] > point[j]) res[i]++;
else if (point[i] < point[j]) res[j]++;
}
}
}
int max = 0;
for (int i = 0; i < n; i++) {
max = Math.max(max, res[i]);
}
return max;
}
}