Re: [閒聊] 每日leetcode
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
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 1276 之 1554 篇):