package com.fishercoder.solutions;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class _929 {
    public static class Solution1 {
        public int numUniqueEmails(String[] emails) {
            Map<String, Set<String>> map = new HashMap<>();
            for (String email : emails) {
                String[] parts = email.split("@");
                if (!map.containsKey(parts[1])) {
                    map.put(parts[1], new HashSet<>());
                }
                String filteredLocalName = parts[0].substring(0, parts[0].indexOf('+'));
                filteredLocalName = filteredLocalName.replace(".", "");
                map.get(parts[1]).add(filteredLocalName);
            }
            int n = 0;
            for (String key : map.keySet()) {
                n += map.get(key).size();
            }
            return n;
        }
    }
}

@@ -762,141 +762,79 @@
     
-int n = 0;%0A            for (String key : map.keySet()) %7B%0A                n += map.get(key).size();%0A            %7D%0A            return n
+return map.keySet().stream().mapToInt(key -%3E map.get(key).size()).sum()
 ;%0A  

refactor 929