Skip to content

Instantly share code, notes, and snippets.

@robsonsky
Created June 24, 2019 21:49
Show Gist options
  • Save robsonsky/df03d3cbb214f0f26b7db28f3d0beeb7 to your computer and use it in GitHub Desktop.
Save robsonsky/df03d3cbb214f0f26b7db28f3d0beeb7 to your computer and use it in GitHub Desktop.
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