Re: [閒聊] 每日leetcode
2924. Find Champion II
## 思路
計算indegree
優勝隊伍的indegree會是0
如果超過兩個隊伍的indegree是0就回傳-1
## Code
```python
class Solution:
def findChampion(self, n: int, edges: List[List[int]]) -> int:
indegree = [0] * n
for _from, _to in edges:
indegree[_to] += 1
res = None
for i in range(n):
if indegree[i] > 0:
continue
if res is not None:
return -1
res = i
return res
```
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 94.156.205.37 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1732621538.A.873.html
討論串 (同標題文章)
完整討論串 (本文為第 1156 之 1548 篇):