997. Find the Town Judge Easy

@problem@discussion
#Array#Hash Table#Graph



1/**
2 * [997] Find the Town Judge
3 *
4 * In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.
5 * If the town judge exists, then:
6 * <ol>
7 * 	The town judge trusts nobody.
8 * 	Everybody (except for the town judge) trusts the town judge.
9 * 	There is exactly one person that satisfies properties 1 and 2.
10 * </ol>
11 * You are given an array trust where trust[i] = [ai, bi] representing that the person labeled ai trusts the person labeled bi.
12 * Return the label of the town judge if the town judge exists and can be identified, or return -1 otherwise.
13 *  
14 * Example 1:
15 * 
16 * Input: n = 2, trust = [[1,2]]
17 * Output: 2
18 * 
19 * Example 2:
20 * 
21 * Input: n = 3, trust = [[1,3],[2,3]]
22 * Output: 3
23 * 
24 * Example 3:
25 * 
26 * Input: n = 3, trust = [[1,3],[2,3],[3,1]]
27 * Output: -1
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= n <= 1000
33 * 	0 <= trust.length <= 10^4
34 * 	trust[i].length == 2
35 * 	All the pairs of trust are unique.
36 * 	ai != bi
37 * 	1 <= ai, bi <= n
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/find-the-town-judge/
43// discuss: https://leetcode.com/problems/find-the-town-judge/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn find_judge(n: i32, trust: Vec<Vec<i32>>) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_997() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.