You are viewing a single comment's thread. Return to all comments →
Sort array then loop through to count pairs:
matches = 0 sortedSocks = sorted(ar)
if n == 1: return 0 i = 0 while i < n - 1: if sortedSocks[i] == sortedSocks[i+1]: matches += 1 i += 2 else: i += 1 return matches
Seems like cookies are disabled on this browser, please enable them to open this website
Sales by Match
You are viewing a single comment's thread. Return to all comments →
Sort array then loop through to count pairs:
matches = 0 sortedSocks = sorted(ar)