728x90
반응형
Solution
- Use Three array hash maps
- Check if element is in at least two array by sum of three array value is over 1
Time Complexity : O(n)
Space Complexity : O(n)
class Solution {
public:
int arrHashMap1[100] = { 0 };
int arrHashMap2[100] = { 0 };
int arrHashMap3[100] = { 0 };
vector<int> twoOutOfThree(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3) {
vector<int> res;
memset(arrHashMap1, 0, sizeof(int) * 100);
memset(arrHashMap2, 0, sizeof(int) * 100);
memset(arrHashMap3, 0, sizeof(int) * 100);
for (int i = 0; i != nums1.size(); ++i)
{
arrHashMap1[nums1[i]] = 1;
}
for (int i = 0; i != nums2.size(); ++i)
{
arrHashMap2[nums2[i]] = 1;
}
for (int i = 0; i != nums3.size(); ++i)
{
arrHashMap3[nums3[i]] = 1;
}
for (int i = 0; i != 100; ++i)
{
if ((arrHashMap1[i] + arrHashMap2[i] + arrHashMap3[i]) > 1)
{
res.push_back(i);
}
else
{
// Do Nothing
}
}
return res;
}
};
728x90
반응형
'코딩 문제' 카테고리의 다른 글
[LeetCode] 1720 Decode XORred Array (0) | 2023.01.29 |
---|---|
[LeetCode] 728. Self Dividing Numbers, C++ (0) | 2023.01.26 |
[Leet Code] 231. Power of Two, C++ (0) | 2023.01.17 |
[LeetCode] 2331. Evaluate Boolean Binary Tree, cpp (0) | 2023.01.10 |
[LeetCode] 1880. Check if Word Equals Summation of Two Words, C (0) | 2023.01.05 |