1 class Solution 2 { 3 public: 4 int numUniqueEmails(vector<string>& emails) 5 { 6 for(int i = 0;i < emails.size();i ++) 7 { 8 for(int j = 0;j < emails[i].size();j ++) 9 { 10 if(emails[i][j]==‘@‘) 11 { 12 for(int k = 0;k < j;k ++) 13 { 14 if(emails[i][k]==‘.‘) 15 { 16 emails[i].erase(k,1); 17 k --; 18 j --; 19 // cout << k << endl; 20 } 21 else if(emails[i][k]==‘+‘) 22 { 23 emails[i].erase(k,j-k); 24 break; 25 } 26 } 27 } 28 } 29 } 30 31 set<string> strSet; 32 for(auto s:emails) 33 strSet.insert(s); 34 return strSet.size(); 35 } 36 };
原文地址:https://www.cnblogs.com/Asurudo/p/9878728.html
时间: 2024-11-14 15:38:17