main.cpp Güncelle
This commit is contained in:
parent
42222089e3
commit
80db0c5f3e
22
main.cpp
22
main.cpp
@ -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
|
||||
}
|
||||
num_map[nums[i]] = i; // Store index of the current number
|
||||
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 {};
|
||||
return uniqueEmails.size();
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user