-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFairCandySwap.java
More file actions
40 lines (38 loc) · 1.11 KB
/
FairCandySwap.java
File metadata and controls
40 lines (38 loc) · 1.11 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
<<<<<<< HEAD
//888. Fair Candy Swap
class Solution {
public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) {
int aliceSum = 0, bobSum = 0;
Set<Integer> set = new HashSet<>();
for(int n : aliceSizes) aliceSum += n;
for(int n : bobSizes){
set.add(n);
bobSum += n;
}
int diff = (aliceSum - bobSum) / 2;
for(int a : aliceSizes){
int b = a - diff;
if(set.contains(b)) return new int[]{a, b};
}
return new int[]{};
}
=======
//888. Fair Candy Swap
class Solution {
public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) {
int aliceSum = 0, bobSum = 0;
Set<Integer> set = new HashSet<>();
for(int n : aliceSizes) aliceSum += n;
for(int n : bobSizes){
set.add(n);
bobSum += n;
}
int diff = (aliceSum - bobSum) / 2;
for(int a : aliceSizes){
int b = a - diff;
if(set.contains(b)) return new int[]{a, b};
}
return new int[]{};
}
>>>>>>> be6ce0b427078b1421d5dd74adb2300dc02daeec
}