1. 程式人生 > >[leetcode] 929. Unique Email Addresses (easy)

[leetcode] 929. Unique Email Addresses (easy)

true als etc 以及 || main bool ast pre

統計有幾種郵箱地址。

郵箱名類型: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(); } };

[leetcode] 929. Unique Email Addresses (easy)