精華區beta Marginalman 關於我們 聯絡資訊
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