1 class Solution { 2 public: 3 vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { 4 set<int> num1; 5 set<int> num2; 6 vector<int> arr; 7 int i = 0; 8 num1.insert(nums1.cbegin(), nums1.cend()); 9 num2.insert(nums2.cbegin(), nums2.cend()); 10 for (const auto &p : num1) 11 { 12 if (num2.find(p) != num2.end()) 13 { 14 arr.push_back(p); 15 } 16 } 17 return arr; 18 } 19 };
标签:arr,num1,num2,交集,nums1,vector,数组,349,nums2 From: https://www.cnblogs.com/lihaoxiang/p/17157249.html