Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
- vector<int> ans;
- sort(nums1.begin(), nums1.end());
- sort(nums2.begin(), nums2.end());
- for (auto i : nums1) {
- if (binary_search(nums2.begin(), nums2.end(), i)) {
- ans.push_back(i);
- }
- }
- int size = unique(ans.begin(), ans.end()) - ans.begin();
- while (ans.size() > size) {
- ans.pop_back();
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement