-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path929.cpp
More file actions
29 lines (25 loc) · 835 Bytes
/
929.cpp
File metadata and controls
29 lines (25 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public:
int numUniqueEmails(vector<string>& emails) {
unordered_map<string, unordered_set<string>> m; //{domain}, {local}
int num = 0;
for(string s : emails){
int atIndex = -1;
for(int i = 0; i < s.length(); i++){
if(s[i] == '@') {atIndex = i; break;}
}
string domain = s.substr(atIndex+1, s.length()-atIndex-1);
string local = "";
for(int i = 0; i < atIndex; i++){
if(s[i] == '.') continue;
if(s[i] == '+') break;
local += s[i];
}
if(m[domain].count(local) == 0){
m[domain].insert(local);
num++;
}
}
return num;
}
};