File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -42,26 +42,21 @@ public int[] fairCandySwap(int[] A, int[] B) {
42
42
int aSum = 0 ;
43
43
int bSum = 0 ;
44
44
int diff = 0 ;
45
- int [] ans = new int [2 ];
46
- for (int bar : A )
47
- {
45
+ int [] ans = new int [2 ];
46
+ for (int bar : A ) {
48
47
aSum += bar ;
49
48
}
50
- for (int bar : B )
51
- {
49
+ for (int bar : B ) {
52
50
bSum += bar ;
53
51
}
54
52
diff = aSum - bSum ;
55
53
HashSet <Integer > set = new HashSet <>();
56
- for (int bar : A )
57
- {
54
+ for (int bar : A ) {
58
55
set .add (bar );
59
56
}
60
- for (int bar : B )
61
- {
62
- if (set .contains (bar + diff /2 ))
63
- {
64
- ans [0 ] = bar + diff /2 ;
57
+ for (int bar : B ) {
58
+ if (set .contains (bar + diff / 2 )) {
59
+ ans [0 ] = bar + diff / 2 ;
65
60
ans [1 ] = bar ;
66
61
break ;
67
62
}
You can’t perform that action at this time.
0 commit comments