🌟Simple Solution to Count Unique Email Addresses 📧
Intuition\n Describe your first thoughts on how to solve this problem. \n---\n\n### Problem Intuition and Solution Explanation\n\n#### Problem Overview\nThe obj
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n---\n\n### Problem Intuition and Solution Explanation\n\n#### Problem Overview\nThe objective is to determine the number of unique email addresses after applying specific normalization rules:\n1. **Ignore Characters After `+`**: Characters following the `+` symbol in the local part of the email should be disregarded.\n2. **Ignore Dots in the Local Part**: Dots in the local part of the email should be removed.\n3. **Preserve the Domain Part**: The domain part (everything after the `@` symbol) should remain unchanged.\n\n#### Solution Approach\n\n1. **Normalization Process**:\n   - **Local Part Processing**:\n     - **Handling `+`**: When the `+` symbol is encountered, discard all characters following it until the `@` symbol. This ensures that aliases created by characters after `+` do not affect the uniqueness of the email.\n     - **Handling `.`**: Remove all `.` characters from the local part, as many email systems ignore dots in this section for uniqueness purposes.\n   - **Domain Part**: Retain the domain part exactly as it appears after the `@` symbol.\n\n2. **Using a Set for Uniqueness**:\n   - **Reason for Using a Set**: To efficiently manage and count unique email addresses, a `set` is employed. The `set` data structure ensures that only unique entries are stored, automatically handling duplicates.\n   - **How It Works**: By inserting each normalized email address into the `set`, any duplicates are automatically discarded. The final count of unique email addresses is determined by the size of the `set`.\n\n#### Detailed Steps:\n\n1. **Iterate Over Each Email Address**:\n   - For each email address, process the local part by skipping characters after `+` and removing dots.\n   - Append the domain part (everything from `@` onwards) to the processed local part.\n\n2. **Store and Count Unique Addresses**:\n   - Insert the fully normalized email into the `set`.\n   - The size of the `set` at the end gives the number of unique email addresses.\n\n### Example\n\nConsider the following email addresses:\n- `"test.email+alex@leetcode.com"`\n- `"test.e.mail+bob.cathy@leetcode.com"`\n- `"testemail+david@lee.tcode.com"`\n\nAfter normalization:\n- `"testemail@leetcode.com"`\n- `"testemail@leetcode.com"`\n- `"testemail@lee.tcode.com"`\n\nThese result in two unique email addresses.\n\n#### Summary\nThe solution uses straightforward string manipulation techniques combined with a `set` to efficiently normalize and count unique email addresses. This method ensures correctness and simplicity, providing an effective approach to solving the problem.\n\n---\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n---\n#### 1. **Understand the Normalization Rules**\n   - **Ignore Characters After `+`**: Characters in the local part after a `+` symbol are considered irrelevant for uniqueness.\n   - **Ignore Dots in the Local Part**: Dots in the local part should be removed as they do not affect the uniqueness of the email address.\n   - **Preserve the Domain Part**: The domain part of the email (everything after the `@` symbol) remains unchanged.\n\n#### 2. **Iterate Through Each Email Address**\n   - **Extract and Process the Local Part**:\n     - **Skip Characters After `+`**: As soon as the `+` symbol is encountered, discard all characters that follow until the `@` symbol.\n     - **Remove Dots**: Continue processing the local part by appending characters to the result, omitting any `.` characters.\n   - **Retain the Domain Part**:\n     - **Extract Domain**: Everything from the `@` symbol onwards is preserved and added to the processed local part.\n\n#### 3. **Utilize a Set for Uniqueness**\n   - **Insert Normalized Emails into a Set**: By storing each normalized email address in a set, duplicates are automatically managed. The `set` data structure ensures that only unique email addresses are counted.\n   - **Count Unique Emails**: The number of unique email addresses is determined by the size of the set after processing all input emails.\n\n#### 4. **Detailed Execution Steps**\n   - **Process Each Email**: For every email in the list:\n     - **Initialize an Empty String for the Local Part**.\n     - **Iterate Through Characters**:\n       - **Skip Unwanted Characters**: After encountering `+`, skip to the `@` symbol.\n       - **Remove Dots**: Append characters to the local part while ignoring dots.\n     - **Extract and Append Domain**: Append the domain part as it is from the `@` symbol to the end of the string.\n   - **Store and Count**: Insert the fully processed email into the set, then compute the number of unique entries based on the set\u2019s size.\n\n### Example Walkthrough\n\nConsider processing the following email addresses:\n- `"test.email+alex@leetcode.com"`\n- `"test.e.mail+bob.cathy@leetcode.com"`\n- `"testemail+david@lee.tcode.com"`\n\nNormalization steps:\n1. **Email 1**:\n   - **Local Part**: `test.email` \u2192 `testemail` (remove `.` and ignore characters after `+`).\n   - **Domain**: `@leetcode.com`\n   - **Normalized Email**: `testemail@leetcode.com`\n\n2. **Email 2**:\n   - **Local Part**: `test.e.mail` \u2192 `testemail` (remove `.` and ignore characters after `+`).\n   - **Domain**: `@leetcode.com`\n   - **Normalized Email**: `testemail@leetcode.com` (same as Email 1)\n\n3. **Email 3**:\n   - **Local Part**: `testemail` \u2192 `testemail` (ignore characters after `+`).\n   - **Domain**: `@lee.tcode.com`\n   - **Normalized Email**: `testemail@lee.tcode.com`\n\nUnique emails: `testemail@leetcode.com`, `testemail@lee.tcode.com`\n\n### Summary\n\nThis approach effectively normalizes email addresses by removing irrelevant characters and using a set to ensure uniqueness. It efficiently handles variations in email formats and provides a straightforward method to count unique addresses.\n\n---\n\n# Complexity\n- Time complexity: **O(m.n)**,where m is the number of email addresses and \nn is the average length of each email.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: **O(m.n)**,where m is the number of email addresses and\nn is the average length of each email.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int numUniqueEmails(vector<string>& emails) {\n         set<string> se;\n    for (int i = 0; i < emails.size(); i++) {\n        string str = emails[i];\n        string s = "";\n        for (int j = 0; j < str.size(); j++) {\n            if (str[j] == \'@\') {\n                s += str.substr(j);\n                break;\n            }\n            if (str[j] == \'.\') continue;\n            if (str[j] == \'+\') {\n                while (str[j] != \'@\') j++;\n                s += str.substr(j);\n                break;\n            }\n            s += str[j];\n        }\n        se.insert(s);\n    }\n    return se.size();\n    }\n};\n```
['C++']