main.cpp Güncelle

This commit is contained in:
Yavuz Sava 2025-03-29 19:20:55 +00:00
parent 42222089e3
commit 80db0c5f3e

View File

@ -1,17 +1,19 @@
#include <unordered_set>
#include <string>
#include <vector>
#include <unordered_map>
class Solution {
public:
std::vector<int> twoSum(std::vector<int>& nums, int target) {
std::unordered_map<int, int> 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
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
}
num_map[nums[i]] = i; // Store index of the current number
}
return {};
return uniqueEmails.size();
}
};