Re: [閒聊] 每日leetcode

看板Marginalman作者 (神楽めあ的錢包)時間1年前 (2024/11/26 20:35), 編輯推噓0(001)
留言1則, 1人參與, 1年前最新討論串1157/1548 (看更多)
2924. Find Champion II 在一個房間內 有n個甲,編號為0~n-1 edges[i]=[u_i,v_i] 表示u_i肛了v_i 然後真正的1是不會被肛的 請問在這個房間內真正的1是誰 因為真正的1只能有1個,所以有2人以上請回傳-1 思路: 就去遍歷edges 記錄每個人被肛過的次數 誰沒被肛過,那個人就是1 如果超過1個就回傳-1 golang code : func findChampion(n int, edges [][]int) int { arr := make([]int, n) for _, val := range edges { arr[val[1]]++ } cnt, ans := 0, 0 for i := 0; i < n; i++ { if arr[i] == 0 { cnt++ ans = i } } if cnt > 1 { return -1 } return ans } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.73.235.139 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1732624514.A.209.html

11/26 20:36, 1年前 , 1F
你是邊被OIN肛邊發這篇的嗎
11/26 20:36, 1F
文章代碼(AID): #1dHS2289 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dHS2289 (Marginalman)