Sales by Match

  • + 0 comments

    Java solution using a Integer, Boolean map. Idea is to negate whatever bool is found in the map for each value. If it isn't already in the map put false. Increment a counter when something is made true. // Write your code here HashMap map = new HashMap<>(); int pairs = 0; System.out.println(map); for(Integer i : ar){ map.put(i, !map.getOrDefault(i,true)); if(map.get(i) == true){pairs++;} } S }

    }