-
Notifications
You must be signed in to change notification settings - Fork 5
/
LC_929_UniqueEmailAddresses.cpp
63 lines (51 loc) · 1.34 KB
/
LC_929_UniqueEmailAddresses.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
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
54
55
56
57
58
59
60
61
62
63
/*
https://leetcode.com/problems/unique-email-addresses/
929. Unique Email Addresses
*/
class Solution {
public:
int numUniqueEmails_1(vector<string>& emails) {
set<string> ue;
string buff="";
for(string email: emails)
{
buff="";
for(char c: email)
{
if(c=='.') continue;
if(c=='+' || c=='@')break;
buff+=c;
}
buff = buff + email.substr(email.find('@'));
ue.insert(buff);
}
return ue.size();
}//end
int numUniqueEmails(vector<string>& emails) {
set<string> ue;
string buff="";
int j=0;
for(string em: emails)
{
buff="";
j=0;
while(em[j] != '@' && em[j]!='+')
{
if(em[j] == '.')
{
j++; continue;
}
buff += em[j];
j++;
}
if(em[j] == '+')
while(em[j]!='@')
j++;
if(em[j] == '@')
buff = buff + em.substr(j);
// cout<<buff<<endl;
ue.insert(buff);
}
return ue.size();
}//end
};