Re: [閒聊] 每日leetcode

作者: dont   2024-11-26 19:45:35
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
```

Links booklink

Contact Us: admin [ a t ] ucptt.com