We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sales by Match
Sales by Match
Sort by
recency
|
6012 Discussions
|
Please Login in order to post a comment
my java solution, all tests pass.
public static int sockMerchant(int n, List ar) { // Write your code here Map map = new HashMap<>(); for(int i=0; i< ar.size(); i++) { if(!map.containsKey(ar.get(i))) map.put(ar.get(i), 1); else { map.put(ar.get(i), map.get(ar.get(i))+1); } } int numPairs=0; Iterator i = map.values().iterator(); while(i.hasNext()) { numPairs = numPairs + (int)i.next()/2; } return numPairs; }
Here is my c++ solution , you can find the video explanation here : https://youtu.be/HPIhFXx_DVM
def sockMerchant(n, ar): pair = 0
Python 3