diff --git a/main.cpp b/main.cpp index 5dc233d..fb39be0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,17 +1,19 @@ +#include +#include #include -#include class Solution { public: - std::vector twoSum(std::vector& nums, int target) { - std::unordered_map num_map; // Stores number and its index - for (int i = 0; i < nums.size(); ++i) { - int complement = target - nums[i]; - if (num_map.find(complement) != num_map.end()) { - return {num_map[complement], i}; // Found the two indices - } - num_map[nums[i]] = i; // Store index of the current number + int numUniqueEmails(std::vector& emails) { + std::unordered_set 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 {}; + return uniqueEmails.size(); } }; \ No newline at end of file