Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間11月前 (2025/01/14 19:16), 編輯推噓1(101)
留言2則, 1人參與, 11月前最新討論串1276/1554 (看更多)
2657. Find the Prefix Common Array of Two Arrays ## 思路 掃Array, 把A[i], B[i]的bit設1 檢查兩個mask &之後的bits數 ## Code ```cpp class Solution { public: vector<int> findThePrefixCommonArray(vector<int>& A, vector<int>& B) { int n = A.size(); bitset<51> maskA=0, maskB=0; vector<int> res(n, 0); for (int i=0; i<n; ++i) { maskA[A[i]] = 1; maskB[B[i]] = 1; res[i] = (maskA & maskB).count(); } return res; } }; ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 89.187.161.77 (日本) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736853371.A.FB1.html

01/14 19:20, 11月前 , 1F
大師
01/14 19:20, 1F

01/14 19:22, 11月前 , 2F
原來這題考位運算喔
01/14 19:22, 2F
文章代碼(AID): #1dXaTx-n (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dXaTx-n (Marginalman)