-
Notifications
You must be signed in to change notification settings - Fork 1
/
FindPlayersWithZeroOrOneLosses.java
39 lines (33 loc) · 1.11 KB
/
FindPlayersWithZeroOrOneLosses.java
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
package com.smlnskgmail.jaman.leetcodejava.medium;
import java.util.*;
// https://leetcode.com/problems/find-players-with-zero-or-one-losses/
public class FindPlayersWithZeroOrOneLosses {
private final int[][] input;
public FindPlayersWithZeroOrOneLosses(int[][] input) {
this.input = input;
}
public List<List<Integer>> solution() {
Set<Integer> zeros = new HashSet<>();
Set<Integer> ones = new HashSet<>();
Set<Integer> marks = new HashSet<>();
for (int[] match : input) {
int w = match[0];
if (!marks.contains(w)) {
zeros.add(w);
}
int l = match[1];
if (!marks.contains(l)) {
ones.add(l);
marks.add(l);
} else {
ones.remove(l);
}
zeros.remove(l);
}
List<Integer> withoutLost = new ArrayList<>(zeros);
List<Integer> withOneLost = new ArrayList<>(ones);
Collections.sort(withoutLost);
Collections.sort(withOneLost);
return List.of(withoutLost, withOneLost);
}
}