My LeetCode grinding. Trying to do a problem a day.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

problem.txt 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.
  2. If the town judge exists, then:
  3. The town judge trusts nobody.
  4. Everybody (except for the town judge) trusts the town judge.
  5. There is exactly one person that satisfies properties 1 and 2.
  6. You are given trust, an array of pairs trust[i] = [a, b] representing that the person labelled a trusts the person labelled b.
  7. If the town judge exists and can be identified, return the label of the town judge. Otherwise, return -1.
  8. Example 1:
  9. Input: N = 2, trust = [[1,2]]
  10. Output: 2
  11. Example 2:
  12. Input: N = 3, trust = [[1,3],[2,3]]
  13. Output: 3
  14. Example 3:
  15. Input: N = 3, trust = [[1,3],[2,3],[3,1]]
  16. Output: -1
  17. Example 4:
  18. Input: N = 3, trust = [[1,2],[2,3]]
  19. Output: -1
  20. Example 5:
  21. Input: N = 4, trust = [[1,3],[1,4],[2,3],[2,4],[4,3]]
  22. Output: 3
  23. Note:
  24. 1 <= N <= 1000
  25. trust.length <= 10000
  26. trust[i] are all different
  27. trust[i][0] != trust[i][1]
  28. 1 <= trust[i][0], trust[i][1] <= N