bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 997. Find the Town Judge

997. Find the Town Judge

Leetcode Solutions

Approach: Two Arrays

  1. Initialize two arrays, indegrees and outdegrees, with a length of n + 1 to account for the 1-based indexing.
  2. Iterate over the trust array, incrementing the outdegree of the trusting person and the indegree of the trusted person.
  3. Iterate from 1 to n and check if there is a person with an indegree of n - 1 and an outdegree of 0.
  4. If such a person is found, return their label as the town judge.
  5. If no town judge is found, return -1.
UML Thumbnail

Approach: One Array

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...