123456789101112131415161718192021222324252627282930313233 |
- class TrustItem:
-
- def __init__(self):
- self.marked = False
- self.trustees = 0
-
- class Solution:
- def findJudge(self, N, trust):
-
- if (len(trust) == 0):
- return 1
-
- trust_results = dict()
- # add to hm key for trusted member
- # mark a key if it trusts someone
- for t in trust:
- if t[0] not in trust_results:
- trust_results[t[0]] = TrustItem()
- trust_results[t[0]].marked = True
-
- if t[1] not in trust_results:
- trust_results[t[1]] = TrustItem()
- trust_results[t[1]].trustees += 1
-
- for key, value in trust_results.items():
- if not value.marked and value.trustees == N - 1:
- return key
-
- return -1
-
- s = Solution()
- print("Expected: 2")
- print("Got:", s.findJudge(2, [[1, 2]]))
|