这个数字好吉利啊!
一句话总结:缺啥补啥
class Solution {
public:
vector<int> fairCandySwap(vector<int>& A, vector<int>& B) {
vector<int>ans;
int sum1 = 0;
int sum2 = 0;
int left = 0;
for(int i = 0;i<A.size();i++) sum1 += A[i];
for(int i = 0;i<B.size();i++) sum2 += B[i];
left = sum1 - (sum1 + sum2)/2;
for(int i = 0;i<A.size();i++)
{
for(int j = 0;j<B.size();j++)
{
if(A[i] - B[j] == left)
{
ans.push_back(A[i]);
ans.push_back(B[j]);
return ans;
}
}
}
return ans;
}
};