1 Star 0 Fork 0

yuhang2__2/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
unique-email-addresses.cpp 698 Bytes
一键复制 编辑 原始数据 按行查看 历史
// Time: O(n * l)
// Space: O(n * l)
class Solution {
public:
int numUniqueEmails(vector<string>& emails) {
unordered_set<string> result;
for (const auto& email : emails) {
result.emplace(convert(email));
}
return result.size();
}
private:
string convert(const string& email) {
const auto& at_it = email.find('@');
const auto& domain = email.substr(at_it);
auto name = email.substr(0, at_it);
name = name.substr(0, name.find('+'));
name.erase(remove(name.begin(), name.end(), '.'), name.end());
auto new_email = move(name);
new_email += domain;
return new_email;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuhang2__2/LeetCode-Solutions.git
git@gitee.com:yuhang2__2/LeetCode-Solutions.git
yuhang2__2
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助