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) {
4242 int aSum = 0 ;
4343 int bSum = 0 ;
4444 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 ) {
4847 aSum += bar ;
4948 }
50- for (int bar : B )
51- {
49+ for (int bar : B ) {
5250 bSum += bar ;
5351 }
5452 diff = aSum - bSum ;
5553 HashSet <Integer > set = new HashSet <>();
56- for (int bar : A )
57- {
54+ for (int bar : A ) {
5855 set .add (bar );
5956 }
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 ;
6560 ans [1 ] = bar ;
6661 break ;
6762 }
You can’t perform that action at this time.
0 commit comments