• + 0 comments

    Java

     public static int sockMerchant(int n, List<Integer> ar) {
            int pairs = 0;
            int size = ar.size();
            while(size-- > 0){
                int sock = ar.get(0);
                ar.remove(0);
    	        if (ar.contains(sock)){
    	            pairs++;
    	            ar.remove(ar.indexOf(sock));
    	            size--;
    	            }
    	        }
            return pairs;
    }