add: 230503
This commit is contained in:
parent
78365bc52a
commit
bfa1062df6
|
|
@ -0,0 +1,36 @@
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
#include <vector>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2215. Find the Difference of Two Arrays
|
||||||
|
*
|
||||||
|
* Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:
|
||||||
|
* answer[0] is a list of all distinct integers in nums1 which are not present in nums2.
|
||||||
|
* answer[1] is a list of all distinct integers in nums2 which are not present in nums1.
|
||||||
|
* Note that the integers in the lists may be returned in any order.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class LC230503 {
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
using V = std::vector<T>;
|
||||||
|
using VVI = V<V<int>>;
|
||||||
|
using CVIR = const V<int>&;
|
||||||
|
|
||||||
|
static VVI findDifference(CVIR, CVIR) noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
LC230503::VVI LC230503::findDifference(CVIR x, CVIR y) noexcept {
|
||||||
|
using USI = std::unordered_set<int>;
|
||||||
|
USI sx(x.begin(), x.end()), sy(y.begin(), y.end());
|
||||||
|
auto proc = [&](const USI& p, const USI& q) {
|
||||||
|
V<int> r;
|
||||||
|
std::copy_if(p.begin(), p.end(), std::back_inserter(r), [&](int n) {
|
||||||
|
return !q.count(n);
|
||||||
|
});
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
return {proc(sx, sy), proc(sy, sx)};
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define LEETCODE_CPP_DEFS_H
|
#define LEETCODE_CPP_DEFS_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class LC230501CN {
|
class LC230501CN {
|
||||||
public:
|
public:
|
||||||
|
|
@ -29,4 +30,14 @@ public:
|
||||||
static bool isValid(const std::string&) noexcept;
|
static bool isValid(const std::string&) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LC230503 {
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
using V = std::vector<T>;
|
||||||
|
using VVI = V<V<int>>;
|
||||||
|
using CVIR = const V<int>&;
|
||||||
|
|
||||||
|
static VVI findDifference(CVIR, CVIR) noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
#endif //LEETCODE_CPP_DEFS_H
|
#endif //LEETCODE_CPP_DEFS_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue