Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/11/26 19:45), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1156/1548 (看更多)
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
文章代碼(AID): #1dHRJYXp (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dHRJYXp (Marginalman)