Unique Email Addresses

 https://leetcode.com/problems/unique-email-addresses/

class Solution {
public:
    int numUniqueEmails(vector<string>& emails) {
         set<string> s;
        for(auto email:emails){
            int i=email.find('@');
            string temp=email.substr(0,i);
            string last=email.substr(i);
            if(temp.find('+')){
                temp=temp.substr(0,temp.find('+'));
            }
            temp.erase(remove(temp.begin(), temp.end(), '.'), temp.end());
            s.insert(temp+last);
        }
        return s.size();
    }
};

Comments

Popular posts from this blog

Perfect Peak of Array

Is Rectangle?

Sort array with squares!