-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetFinder.cpp
More file actions
43 lines (38 loc) · 1.14 KB
/
setFinder.cpp
File metadata and controls
43 lines (38 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <numeric>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
vector<int> fairCandySwap(vector<int>& aliceSizes, vector<int>& bobSizes) {
vector<int> ans;
int alzSum = accumulate(aliceSizes.begin(),aliceSizes.end(),0);
int bobSum = accumulate(bobSizes.begin(),bobSizes.end(),0);
int diff = alzSum - bobSum;
int compensation = diff / 2;
// multiset<int> bobSet(bobSizes.get_allocator());
for(int i : aliceSizes){
// if(bobSizes.find(i - compensation) != bobSizes.end()) {
if(find(bobSizes.begin(), bobSizes.end(), i - compensation) != bobSizes.end()) {
ans.push_back(i);
ans.push_back(i - compensation);
return ans;
}
}
return ans;
}
};
int main() {
vector<int> aliceSizes = {1, 1};
vector<int> bobSizes = {2, 2};
Solution sol;
vector<int> result = sol.fairCandySwap(aliceSizes, bobSizes);
cout << "Result: ";
for (int num : result) {
cout << num << " ";
}
cout << endl;
return 0;
}