-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path2923.Find-champion-i.java
36 lines (31 loc) · 1000 Bytes
/
2923.Find-champion-i.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
// https://leetcode.com/problems/find-champion-i/description/
// algorithms
// Easy (71.64%)
// Total Accepted: 24K
// Total Submissions: 33.5K
class Solution {
public int findChampion(int[][] grid) {
Set<Integer> loserSet = new HashSet<>();
Set<Integer> winnerSet = new HashSet<>();
int n = grid.length;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (grid[i][j] == 0) {
if (!loserSet.contains(j)) {
winnerSet.add(j);
}
winnerSet.remove(i);
loserSet.add(i);
} else {
if (!loserSet.contains(i)) {
winnerSet.add(i);
}
winnerSet.remove(j);
loserSet.add(j);
}
}
}
List<Integer> res = new ArrayList<>(winnerSet);
return res.get(0);
}
}