You are viewing a single comment's thread. Return to all comments →
Hashset storing values by placing values into an array by an index calculated according to GetHashCode of the value.
Actually I had the same idea but simpler:
int[] pairsToSell = new int[n]; int countToSell = 0; foreach(int sock in socks) { var ind = sock % n; pairsToSell[ind] +=1; if (pairsToSell[ind] == 2) { countToSell++; pairsToSell[ind] = 0; } } Console.WriteLine(countToSell);
Since sock color is a positive integer number, there is no need to take hash code of it. Instead I just used sock%n to recognize appropriate index.
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 →
Hashset storing values by placing values into an array by an index calculated according to GetHashCode of the value.
Actually I had the same idea but simpler:
Since sock color is a positive integer number, there is no need to take hash code of it. Instead I just used sock%n to recognize appropriate index.