problem
solution:
class Solution { public: vector<int> fairCandySwap(vector<int>& A, vector<int>& B) { int sumA = 0, sumB = 0, delta = 0; unordered_set<int> setA; for(auto a:A) { sumA += a; setA.insert(a);//err... } for(auto b:B) sumB += b; delta = (sumA-sumB)/2; for(auto b:B) { if(setA.count(delta+b)) return {delta+b, b}; } return vector<int>(); } };
参考
1. Leetcode_easy_888. Fair Candy Swap;
2. discuss;
3. grandyang;
完