Created
July 4, 2020 13:56
-
-
Save facekunal/ff8a8fdbd34725cc4cde9719852d1db4 to your computer and use it in GitHub Desktop.
Swapping pair make sums equal - Naive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean isEqualSum(int[] a, int[] b) { | |
int sumA = Arrays.stream(a).sum(); | |
int sumB = Arrays.stream(b).sum(); | |
for(int i=0;i<a.length;i++){ | |
for(int j=0;j<b.length;j++) { | |
if (sumA - a[i] + b[j] == sumB - b[j] + a[i]) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment