19 lines
779 B
C++
19 lines
779 B
C++
#include <unordered_set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class Solution {
|
|
public:
|
|
int numUniqueEmails(std::vector<std::string>& emails) {
|
|
std::unordered_set<std::string> uniqueEmails;
|
|
for (const auto& email : emails) {
|
|
int atPos = email.find('@');
|
|
std::string local = email.substr(0, atPos);
|
|
std::string domain = email.substr(atPos);
|
|
local.erase(std::remove(local.begin(), local.end(), '.'), local.end()); // Remove '.' characters in the local part
|
|
local = local.substr(0, local.find('+')); // Remove everything after the first '+' in the local part
|
|
uniqueEmails.insert(local + domain); // Combine back to form the unique email
|
|
}
|
|
return uniqueEmails.size();
|
|
}
|
|
}; |