mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 01:44:56 +08:00
add: leetcode 0997 solution
This commit is contained in:
22
leetcode/0997.Find-the-Town-Judge/997.Find the Town Judge.go
Normal file
22
leetcode/0997.Find-the-Town-Judge/997.Find the Town Judge.go
Normal file
@ -0,0 +1,22 @@
|
||||
package leetcode
|
||||
|
||||
func findJudge(n int, trust [][]int) int {
|
||||
if n == 1 && len(trust) == 0 {
|
||||
return 1
|
||||
}
|
||||
judges := make(map[int]int)
|
||||
for _, v := range trust {
|
||||
judges[v[1]] += 1
|
||||
}
|
||||
for _, v := range trust {
|
||||
if _, ok := judges[v[0]]; ok {
|
||||
delete(judges, v[0])
|
||||
}
|
||||
}
|
||||
for k, v := range judges {
|
||||
if v == n-1 {
|
||||
return k
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
Reference in New Issue
Block a user