-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm2225.java
More file actions
78 lines (69 loc) · 2.8 KB
/
prblm2225.java
File metadata and controls
78 lines (69 loc) · 2.8 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.*;
public class prblm2225 {
public static List<List<Integer>> findWinners(int[][] matches) {
Map<Integer, Integer> map = new HashMap<>();
for (var e : matches) {
map.putIfAbsent(e[0], 0);
map.merge(e[1], 1, Integer::sum);
}
System.out.println(map);
List<List<Integer>> ans = List.of(new ArrayList<>(), new ArrayList<>());
for (var e : map.entrySet()) {
if (e.getValue() < 2) {
ans.get(e.getValue()).add(e.getKey());
}
}
Collections.sort(ans.get(0));
Collections.sort(ans.get(1));
return ans;
}
public static void main(String[] args) {
int[][] matches = {{1,3},{2,3},{3,6},{5,6},{5,7},{4,5},{4,8},{4,9},{10,4},{10,9}};
List<List<Integer>> list = new ArrayList<>();
list = findWinners(matches);
for (List<Integer> game : list) {
System.out.println(game);
}
}
}
// import java.util.*;
// public class prblm2225 {
// public static List<List<Integer>> findWinners(int[][] matches) {
// Map<Integer,Integer> winMap = new HashMap<>();
// Map<Integer,Integer> loseMap = new HashMap<>();
// for(int i = 0; i < matches.length; i++){
// winMap.put(matches[i][0], winMap.getOrDefault(matches[i][0], 0) + 1);
// loseMap.put(matches[i][1], loseMap.getOrDefault(matches[i][1], 0) + 1);
// }
// System.out.println(winMap);
// System.out.println(loseMap);
// List<Integer> winner = new ArrayList<>();
// List<Integer> loser = new ArrayList<>();
// List<List<Integer>> winOrLose = new ArrayList<>();
// for(int i = 0; i < matches.length; i++){
// for (int j = 0; j < matches[i].length; j++) {
// if (winMap.containsKey(matches[i][j]) && !loseMap.containsKey(matches[i][j]) && !winner.contains(matches[i][j])) {
// winner.add(matches[i][j]);
// }
// else if (loseMap.containsKey(matches[i][j]) && !loser.contains(matches[i][j])) {
// if (loseMap.get(matches[i][j]) == 1) {
// loser.add(matches[i][j]);
// }
// }
// }
// }
// Collections.sort(winner);
// Collections.sort(loser);
// winOrLose.add(winner);
// winOrLose.add(loser);
// return winOrLose;
// }
// public static void main(String[] args) {
// int[][] matches = {{1,3},{2,3},{3,6},{5,6},{5,7},{4,5},{4,8},{4,9},{10,4},{10,9}};
// List<List<Integer>> list = new ArrayList<>();
// list = findWinners(matches);
// for (List<Integer> game : list) {
// System.out.println(game);
// }
// }
// }