统计有几种邮箱地址。
邮箱名类型:local@domain
规则:1. local中出现"."的,忽略。 a.bc=abc
2. local中出现"+"的,+以及之后的local全部忽略。 a+bc=a
思路:
利用set存,水题没啥好说的
Runtime: 20 ms, faster than 96.66% of C++ online submissions for Unique Email Addresses.
class Solution
{
public:
int numUniqueEmails(vector<
string> &
emails)
{
set<
string>
aset;
for (
string s : emails)
{
bool local =
true;
bool hasPlus =
false;
string temp=
"";
for (
char c : s)
{
if (c ==
'@')
local =
false;
if (c ==
'+' &&
local)
hasPlus =
true;
if ((c ==
'.' || hasPlus) &&
local)
continue;
temp.push_back(c);
}
aset.insert(temp);
}
return aset.size();
}
};
转载于:https://www.cnblogs.com/ruoh3kou/p/10037376.html
相关资源:数据结构—成绩单生成器