Skip to content

Commit 33ca2ba

Browse files
authored
Create 2225. Find Players With Zero or One Losses.java
1 parent 39034c5 commit 33ca2ba

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Runtime 74ms
2+
// Beats 80.96%
3+
4+
// Memory 107.66MB
5+
// Beats 17.11%
6+
7+
class Solution {
8+
public List<List<Integer>> findWinners(int[][] matches) {
9+
Set<Integer> win=new HashSet<>();
10+
Map<Integer,Integer> los=new HashMap<>();
11+
12+
for(int[] mat:matches){
13+
los.put(mat[1],los.getOrDefault(mat[1] , 0)+1);
14+
}
15+
16+
for(int[] mat:matches){
17+
if(!los.containsKey(mat[0]))
18+
win.add(mat[0]);
19+
}
20+
21+
List<Integer> winList=new ArrayList<>(win);
22+
List<Integer> losList=new ArrayList<>();
23+
24+
for(int loss:los.keySet()){
25+
if(los.get(loss)==1)
26+
losList.add(loss);
27+
}
28+
29+
Collections.sort(winList);
30+
Collections.sort(losList);
31+
32+
List<List<Integer>> res=new ArrayList<>();
33+
res.add(winList);
34+
res.add(losList);
35+
36+
return res;
37+
38+
}
39+
}

0 commit comments

Comments
 (0)