mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	国外版
This commit is contained in:
		
							
								
								
									
										47
									
								
								算法题(国外版)/find-the-town-judge.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								算法题(国外版)/find-the-town-judge.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
<p>In a town, there are <code>n</code> people labeled from <code>1</code> to <code>n</code>. There is a rumor that one of these people is secretly the town judge.</p>
 | 
			
		||||
 | 
			
		||||
<p>If the town judge exists, then:</p>
 | 
			
		||||
 | 
			
		||||
<ol>
 | 
			
		||||
	<li>The town judge trusts nobody.</li>
 | 
			
		||||
	<li>Everybody (except for the town judge) trusts the town judge.</li>
 | 
			
		||||
	<li>There is exactly one person that satisfies properties <strong>1</strong> and <strong>2</strong>.</li>
 | 
			
		||||
</ol>
 | 
			
		||||
 | 
			
		||||
<p>You are given an array <code>trust</code> where <code>trust[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> representing that the person labeled <code>a<sub>i</sub></code> trusts the person labeled <code>b<sub>i</sub></code>.</p>
 | 
			
		||||
 | 
			
		||||
<p>Return <em>the label of the town judge if the town judge exists and can be identified, or return </em><code>-1</code><em> otherwise</em>.</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> n = 2, trust = [[1,2]]
 | 
			
		||||
<strong>Output:</strong> 2
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 2:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> n = 3, trust = [[1,3],[2,3]]
 | 
			
		||||
<strong>Output:</strong> 3
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 3:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> n = 3, trust = [[1,3],[2,3],[3,1]]
 | 
			
		||||
<strong>Output:</strong> -1
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Constraints:</strong></p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li><code>1 <= n <= 1000</code></li>
 | 
			
		||||
	<li><code>0 <= trust.length <= 10<sup>4</sup></code></li>
 | 
			
		||||
	<li><code>trust[i].length == 2</code></li>
 | 
			
		||||
	<li>All the pairs of <code>trust</code> are <strong>unique</strong>.</li>
 | 
			
		||||
	<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
 | 
			
		||||
	<li><code>1 <= a<sub>i</sub>, b<sub>i</sub> <= n</code></li>
 | 
			
		||||
</ul>
 | 
			
		||||
		Reference in New Issue
	
	Block a user