-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path929.cpp
More file actions
34 lines (34 loc) · 970 Bytes
/
929.cpp
File metadata and controls
34 lines (34 loc) · 970 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
30
31
32
33
34
class Solution {
public:
string emailParser(string& email) {
string out;
int index = 0;
int n = email.size();
bool beforeAt = true;
while (index < n) {
if (email[index] == '.') {
if (!beforeAt) out.push_back(email[index]);
}
else if (email[index] == '+' && beforeAt) {
while (index + 1 < n && email[index + 1] != '@') index++;
}
else if (email[index] == '@') {
beforeAt = false;
out.push_back(email[index]);
}
else {
out.push_back(email[index]);
}
index++;
}
return out;
}
int numUniqueEmails(vector<string>& emails) {
unordered_set<string> st;
for (auto email : emails) {
string refined = emailParser(email);
st.insert(refined);
}
return st.size();
}
};