Re: [閒聊] 每日leetcode
看板Marginalman作者DJYOSHITAKA (franchouchouISBEST)時間1年前 (2024/03/10 14:01)推噓2(2推 0噓 6→)留言8則, 4人參與討論串30/1548 (看更多)
最近好多easy 又水了一天
亂寫一通
349. Intersection of Two Arrays
Given two integer arrays nums1 and nums2, return an array of their
intersection. Each element in the result must be unique and you may return
the result in any order.
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
vector<int> cnt(1001,0);
unordered_set<int> a;
unordered_set<int> b;
vector<int> ans;
for(auto i : nums1)
{
a.insert(i);
}
for(auto i : nums2)
{
b.insert(i);
}
for(auto i : a)
{
cnt[i]++;
}
for(auto i : b)
{
cnt[i]--;
if(cnt[i] == 0)
{
ans.push_back(i);
}
}
return ans;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.228.146.144 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1710050476.A.AF2.html
※ 編輯: DJYOSHITAKA (125.228.146.144 臺灣), 03/10/2024 14:01:26
推
03/10 14:06,
1年前
, 1F
03/10 14:06, 1F
→
03/10 14:08,
1年前
, 2F
03/10 14:08, 2F
推
03/10 14:14,
1年前
, 3F
03/10 14:14, 3F
→
03/10 14:15,
1年前
, 4F
03/10 14:15, 4F
→
03/10 14:16,
1年前
, 5F
03/10 14:16, 5F
→
03/10 14:18,
1年前
, 6F
03/10 14:18, 6F
→
03/10 14:19,
1年前
, 7F
03/10 14:19, 7F
→
03/10 14:31,
1年前
, 8F
03/10 14:31, 8F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 30 之 1548 篇):