Sort by

recency

|

6067 Discussions

|

  • + 0 comments

    public static int sockMerchant(int n, List ar) { return ar.stream() .collect(Collectors.groupingBy(c -> c, Collectors.counting())) .values() .stream() .mapToInt(count -> (int)(count / 2)) .sum(); }

  • + 0 comments

    public static int sockMerchant(int n, List ar) { return ar.stream() .collect(Collectors.groupingBy(c -> c, Collectors.counting())) .values() .stream() .mapToInt(count -> (int)(count / 2)) .sum(); }

  • + 0 comments

    The "i don't type for free way"-

    return sum(v // 2 for v in counts.values())
    
  • + 0 comments

    There are two ways to solve this with Counter: The normal way-

    # result = 0
        # for a in ar.values():
        #     result += int(a/2)
        # return result
    
  • + 0 comments
    def sockMerchant(n, ar):
        arr=ar
        ans=[]
        arr=list(set(arr))
        for i in arr:
            ans.append(ar.count(i)//2)
        return sum(ans)