Re: [閒聊] 每日leetcode

看板Marginalman作者 (神楽めあ的錢包)時間10月前 (2025/01/20 21:38), 編輯推噓2(200)
留言2則, 2人參與, 10月前最新討論串1294/1552 (看更多)
2661. First Completely Painted Row or Column 思路: 就記錄每個數字所在的行、列 接著去遍歷arr 看哪一行、哪一列先湊齊 沒什麼難度 golang code : func firstCompleteIndex(arr []int, mat [][]int) int { n, m := len(mat), len(mat[0]) rec := make([][2]int, len(arr)+1) cnt := make([]int, n+m) for i := 0; i < n; i++ { for j := 0; j < m; j++ { rec[mat[i][j]] = [2]int{i, j + n} } } for key, val := range arr { cnt[rec[val][0]]++ cnt[rec[val][1]]++ if cnt[rec[val][0]] == m || cnt[rec[val][1]] == n { return key } } return -1 } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.72.238.230 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1737380294.A.585.html

01/20 21:38, 10月前 , 1F
大師
01/20 21:38, 1F

01/20 21:43, 10月前 , 2F
卷爽沒
01/20 21:43, 2F
文章代碼(AID): #1dZb76M5 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dZb76M5 (Marginalman)