Re: [閒聊] 每日leetcode

看板Marginalman作者 (三角初華的事件視界)時間10月前 (2025/01/14 23:56), 編輯推噓0(002)
留言2則, 2人參與, 10月前最新討論串1279/1549 (看更多)
※ 引述《dont (dont)》之銘言: : 2657. Find the Prefix Common Array of Two Arrays : ## 思路 : 掃Array, 把A[i], B[i]的bit設1 : 檢查兩個mask &之後的bits數 好久沒寫 腦袋當機 邊看邊復健 解說跟我說用HashSet Code: use std::collections::HashSet; impl Solution { pub fn find_the_prefix_common_array(a: Vec<i32>, b: Vec<i32>) -> Vec<i32> { let mut seen = HashSet::new(); let mut common_count = 0; let mut result = Vec::with_capacity(a.len()); for (&x, &y) in a.iter().zip(b.iter()) { if seen.contains(&x) { common_count += 1; } else { seen.insert(x); } if seen.contains(&y) { common_count += 1; } else { seen.insert(y); } result.push(common_count); } result } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.193.249.242 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736870173.A.02D.html

01/15 00:00, 10月前 , 1F
別卷了
01/15 00:00, 1F

01/15 09:19, 10月前 , 2F
別卷了
01/15 09:19, 2F
文章代碼(AID): #1dXeaT0j (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dXeaT0j (Marginalman)