929. 独特的电子邮件地址

 1 //1、除了小写字母,这些电子邮件还可能包含 '.' 或 '+'
 2 //2、每封 emails[i] 都包含有且仅有一个 '@' 字符
 3 //3、只考虑本地名称,即'@'字符以前的
 4 class Solution 
 5 {
 6 public:
 7     int numUniqueEmails(vector<string>& emails) 
 8     {
 9         unordered_set<string> hash;
10         for(int i = 0;i < emails.size();i ++)
11         {
12             string str = emails[i];
13             int index = str.find('@');
14             string temp;
15             for(int j = 0;j < index;j ++)
16             {
17                 if(str[j] == '.') continue;
18                 else if(str[j] == '+') break;
19                 else temp.push_back(str[j]);
20             }
21             temp += str.substr(index);
22             hash.insert(temp);
23         }
24         return hash.size();
25     }
26 };

 

posted @ 2020-03-24 18:36  Jinxiaobo0509  阅读(156)  评论(0)    收藏  举报