[C++] Linear Solution Explained, 100% Time, ~99% Space
To solve this problem we will just have to clean up our strings, then use something to remove duplicated - an unordered_set works just fine for that.\n\nSo, our
To solve this problem we will just have to clean up our strings, then use something to remove duplicated - an `unordered_set` works just fine for that.\n\nSo, our support variables are going to be:\n* `tmp`, the string we will build gradually as we clean up each provided one;\n* `res` is going to be our aforementioned set, convenient to store and avoid duplicates in `O(lgn)`;\n* `beforeAt` and `plusSeen` are two boolean flags will use to mark specific points in each email.\n\nWe will then loop through each string `s` given to us and:\n* clear `tmp`, ready for another loop;\n*  reset `beforeAt` and `plusSeen` to be `true` and `false`, respectively;\n*  loops through each character `c` of `s` and:\n\t*  if `c` is a `\'+\'`, set `plusSeen` to `true`;\n\t*  alternatively, if `c` is `@\'`, set `beforeAt` to `false` and reset `plusSeen` to `false`;\n\t*  check if we found a `\'.\'` before the `\'@\'` (`beforeAt && c == \'.\'`) or if we are after a `\'+\'` (`plusSeen`), in which case we just `continue`;\n\t*  append `c` to `tmp`;\n*  finally, insert `tmp` in `res`.\n\nOnce done, we can just `return` `res.size()` to get the uniques and be done with it :)\n\nThe code:\n\n```cpp\nclass Solution {\npublic:\n    int numUniqueEmails(vector<string>& emails) {\n        // support variables\n        string tmp;\n        unordered_set<string> res;\n        bool beforeAt, plusSeen;\n        // parsing emails\n        for (string &s: emails) {\n            // resetting loop variables\n            tmp.clear();\n            beforeAt = true, plusSeen = false;\n            for (char c: s) {\n                if (c == \'+\') plusSeen = true;\n                else if (c == \'@\') beforeAt = false, plusSeen = false;\n                if (beforeAt && c == \'.\' || plusSeen) continue;\n                tmp += c;\n            }\n            res.insert(tmp);\n        }\n        return res.size();\n    }\n};\n```
['String', 'C', 'C++']