Re: [闲聊] 每日LeetCode

楼主: JerryChungYC (JerryChung)   2024-02-22 20:51:24
https://leetcode.com/problems/find-the-town-judge/
997. Find the Town Judge
小镇上有n个人被标记为1到n,传言其中有1个人是镇法官
如果镇法官存在:
1. 镇法官不相信任何人
2. 除了镇法官以外的每个人都信任镇法官
3. 恰好有一个人满足性质1和2
给一个信任数组,trust[i] = [ai, bi]表示标记为ai的人信任标记为bi的人
如果镇法官存在,则传回镇法官的标签,否则传回-1
Example 1:
Input: n = 2, trust = [[1,2]]
Output: 2
Example 2:
Input: n = 3, trust = [[1,3],[2,3]]
Output: 3
Example 3:
Input: n = 3, trust = [[1,3],[2,3],[3,1]]
Output: -1
Python3 code:

Links booklink

Contact Us: admin [ a t ] ucptt.com