From 80db0c5f3e97a99d06d4714f191504c8a02a8fb6 Mon Sep 17 00:00:00 2001 From: Yavuz Sava Date: Sat, 29 Mar 2025 19:20:55 +0000 Subject: [PATCH] =?UTF-8?q?main.cpp=20G=C3=BCncelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) 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