We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3ce326c commit 6d4ba7aCopy full SHA for 6d4ba7a
929/step2_1_fix.cpp
@@ -0,0 +1,24 @@
1
+/*
2
+
3
+*/
4
+class Solution {
5
+ public:
6
+ int numUniqueEmails(vector<string>& emails) {
7
+ for (auto& email : emails) {
8
+ canonicalize_email(email);
9
+ }
10
+ set<string> unique_emails(emails.begin(), emails.end());
11
+ return unique_emails.size();
12
13
14
+ private:
15
+ void canonicalize_email(string& email) {
16
+ auto at_pos = email.rfind('@');
17
+ string local_part = email.substr(0, at_pos);
18
+ auto plus_pos = local_part.find('+');
19
+ string canonicalized_local_part = local_part.substr(0, plus_pos);
20
+ std::erase(canonicalized_local_part, '.');
21
+ string domain_part = email.substr(at_pos, email.size() - at_pos);
22
+ email = canonicalized_local_part + domain_part;
23
24
+};
0 commit comments