forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.cpp
25 lines (25 loc) · 797 Bytes
/
solution.cpp
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
class Solution {
public:
int numUniqueEmails(vector<string>& emails) {
set<string> mailset;
for(int i=0;i<emails.size();i++){
bool beforeAt = true;
bool afterPlus = false;
string temp;
for(int j=0;j<emails[i].size();j++){
if(emails[i][j] == '@'){
temp += emails[i][j];
beforeAt = false;
}
if(beforeAt && emails[i][j] == '+')
afterPlus = true;
if(beforeAt && !afterPlus && emails[i][j] != '.')
temp += emails[i][j];
if(!beforeAt)
temp += emails[i][j];
}
mailset.insert(temp);
}
return mailset.size();
}
};