Created
June 30, 2019 08:55
-
-
Save gauravbansal74/5f1bc40857589a522451f8fc9db71ca4 to your computer and use it in GitHub Desktop.
Sock Merchant || HackerRank
This file contains hidden or 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
static int sockMerchant(int n, int[] arr) { | |
Set<Integer> colors = new HashSet<>(); | |
int pairs = 0; | |
if(n == arr.length){ | |
for (int i = 0; i < n; i++) { | |
if (colors.remove(arr[i])) { | |
pairs++; | |
} else { | |
colors.add(arr[i]); | |
} | |
} | |
} | |
return pairs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment