-
Notifications
You must be signed in to change notification settings - Fork 0
/
929. Unique Email Addresses
53 lines (50 loc) · 1.48 KB
/
929. Unique Email Addresses
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Solution {
public:
int numUniqueEmails(vector<string>& emails) {
vector<string> locals;
vector<int> visit;
int i = 0, size = emails.size(), j = 0, div = 0, count = 0;
for(i = 0; i < size; i++){
int strSize = emails[i].size();
string localReal, domainReal, finalReal;
for(j = 0; j < strSize; j++){
if(emails[i][j] == '@'){
break;
}
}
div = j;
for(j = 0; j < div; j++){
if(emails[i][j] == '+'){
break;
}
if(emails[i][j] == '.'){
continue;
}
localReal += emails[i][j];
}
for(j = div + 1; j < strSize; j++){
domainReal += emails[i][j];
}
finalReal = localReal + '@' + domainReal;
// cout << finalReal << endl;
locals.push_back(finalReal);
visit.push_back(0);
}
for(i = 0; i < size; i++){
if(visit[i] == 1){
continue;
}
visit[i] = 1;
count++;
for(j = i+1; j < size; j++){
if(visit[j] == 1){
continue;
}
if(locals[i] == locals[j]){
visit[j] = 1;
}
}
}
return count;
}
};