Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Feb 22, 2024
1 parent be27d2a commit c35af1e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions leetcode/997.FindtheTownJudge/findtheTownJudge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// https://leetcode.com/problems/find-the-town-judge

package main

import (
"fmt"
)

func findJudge(n int, trust [][]int) int {
if n == 1 && len(trust) == 0 {
return 1
}

m := make(map[int]int)

for _, t := range trust {
m[t[0]]--
m[t[1]]++
}

for i := 1; i <= n; i++ {
if m[i] == n-1 {
return i
}
}

return -1
}

func main() {
n := 4
trust := [][]int{{1, 3}, {1, 4}, {2, 3}, {2, 4}, {4, 3}}

fmt.Println(findJudge(n, trust))
}

0 comments on commit c35af1e

Please sign in to comment.