Created
June 24, 2019 21:49
-
-
Save robsonsky/df03d3cbb214f0f26b7db28f3d0beeb7 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
func findPairs(ar: [Int], pairs: Int) -> Int { | |
var res = pairs | |
if ar.count > 0 { | |
var newAr = ar | |
let sock = newAr.remove(at: 0) | |
for (index, element) in newAr.enumerated() { | |
if element == sock { | |
newAr.remove(at: index) | |
res += 1 | |
break | |
} | |
} | |
return findPairs(ar: newAr, pairs: res) | |
} | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment