2225. Find Players With Zero or One Losses Medium
1/**
2 * [2225] Find Players With Zero or One Losses
3 *
4 * You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.
5 * Return a list answer of size 2 where:
6 *
7 * answer[0] is a list of all players that have not lost any matches.
8 * answer[1] is a list of all players that have lost exactly one match.
9 *
10 * The values in the two lists should be returned in increasing order.
11 * Note:
12 *
13 * You should only consider the players that have played at least one match.
14 * The testcases will be generated such that no two matches will have the same outcome.
15 *
16 *
17 * Example 1:
18 *
19 * Input: matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]
20 * Output: [[1,2,10],[4,5,7,8]]
21 * Explanation:
22 * Players 1, 2, and 10 have not lost any matches.
23 * Players 4, 5, 7, and 8 each have lost one match.
24 * Players 3, 6, and 9 each have lost two matches.
25 * Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].
26 *
27 * Example 2:
28 *
29 * Input: matches = [[2,3],[1,3],[5,4],[6,4]]
30 * Output: [[1,2,5,6],[]]
31 * Explanation:
32 * Players 1, 2, 5, and 6 have not lost any matches.
33 * Players 3 and 4 each have lost two matches.
34 * Thus, answer[0] = [1,2,5,6] and answer[1] = [].
35 *
36 *
37 * Constraints:
38 *
39 * 1 <= matches.length <= 10^5
40 * matches[i].length == 2
41 * 1 <= winneri, loseri <= 10^5
42 * winneri != loseri
43 * All matches[i] are unique.
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/find-players-with-zero-or-one-losses/
49// discuss: https://leetcode.com/problems/find-players-with-zero-or-one-losses/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn find_winners(matches: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
55 vec![]
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_2225() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.