|
class Solution {
public:
vector<int> intersection(vector<vector<int>>& nums) {
if(nums.size()==1){
sort(nums[0].begin(), nums[0].end());
return nums[0];
}
vector<int> ans;
vector<unordered_set<int>> set(nums.size());
for(int i = 1; i < nums.size(); ++i)
{
for(auto x : nums[i])
set[i].insert(x);
}
for(auto x : nums[0])
{
bool inall = true;
for(int i = 1; i < set.size(); ++i)
{
if(set[i].find(x) == set[i].end())
{
inall = false;
break;
}
}
if(inall)
ans.push_back(x);
}
sort(ans.begin(), ans.end());
return ans;
}
}; |
|