[leetcode] 929. Unique Email Addresses (easy)

Posted Ruoh3kou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[leetcode] 929. Unique Email Addresses (easy)相关的知识,希望对你有一定的参考价值。

统计有几种邮箱地址。

邮箱名类型:[email protected]

规则: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();
  }
};

 

以上是关于[leetcode] 929. Unique Email Addresses (easy)的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 929 Unique Email Addresses 解题报告

[LeetCode] 929. Unique Email Addresses 独特的邮件地址

929. Unique Email Addresses

LeetCode --- 929. Unique Email Addresses 解题报告

[leetcode] 929. Unique Email Addresses (easy)

LeetCode 929. Unique Email Addresses (独特的电子邮件地址)