Created
December 19, 2019 21:33
-
-
Save joelbarbosa/dd8a0a87518d9846aa2dbff38163ce51 to your computer and use it in GitHub Desktop.
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
// Return the total number of matching pairs of socks that John can sell. | |
// 9 | |
// 10 20 20 10 10 30 50 10 20 | |
// output | |
// 3 | |
function sockMerchant(n, ar) { | |
let totalPair=0; | |
const pairs = new Set(); | |
for (let i=0; i <= n; i++) { | |
if (!pairs.has(ar[i])) { | |
pairs.add(ar[i]); | |
} else { | |
totalPair++; | |
pairs.delete(ar[i]); | |
} | |
} | |
return totalPair; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment