-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path929. Unique Email Addresses.cpp
More file actions
33 lines (33 loc) · 1.02 KB
/
Copy path929. Unique Email Addresses.cpp
File metadata and controls
33 lines (33 loc) · 1.02 KB
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
class Solution {
public:
int numUniqueEmails(vector<string>& emails) {
set<string> st;
for(int i=0; i<emails.size(); i++){
string str = "";
bool plus = false, atThe = false;
for(int j=0; j<emails[i].size(); j++){
if(!plus){
// if plus is not found yet
if(emails[i][j] == '.' && !atThe) continue;
else{
if(emails[i][j] == '+' && !atThe){
plus = true;
}
else str += emails[i][j];
}
}
else{
// if plus is found then find the @
if(emails[i][j] == '@'){
plus = false;
atThe = true;
str += '@';
}
}
}
//cout << str << endl;
st.insert(str);
}
return st.size();
}
};