class Solution {
public int numUniqueEmails(String[] emails) {
// int res = 0;
HashMap<String, Integer> map = new HashMap<>();
for( String s : emails ){
int ind = s.indexOf("@");
String local = s.substring(0, ind);
String domain = s.substring(ind + 1);
String tmp = "";
int l = local.length();
for( int i = 0 ; i < l ; i ++ ){
char c = local.charAt(i);
if( c >= 'a' && c <= 'z')tmp += c;
if( c >= '0' && c <= '9')tmp += c;
if( c == '.' )continue;
if( c == '+' )break;
}
tmp += domain;
map.put(tmp, map.getOrDefault(tmp, 0) + 1);
}
return map.size();
}
}
我用的 HashMap实现的,看了一下submission里面的有的使用HashSet