[Leetcode]929. Unique Email Addresses

929. Unique Email Addresses

Every email consists of a local name and a domain name, separated by the @ sign.

For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name.

Besides lowercase letters, these emails may contain '.'s or '+'s.

If you add periods ('.') between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. For example, "alice.z@leetcode.com"and "alicez@leetcode.com" forward to the same email address. (Note that this rule does not apply for domain names.)

If you add a plus ('+') in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered, for example m.y+name@email.com will be forwarded to my@email.com. (Again, this rule does not apply for domain names.)

It is possible to use both of these rules at the same time.

Given a list of emails, we send one email to each address in the list. How many different addresses actually receive mails?

Input: ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]
Output: 2
Explanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails

Note:

  • 1 <= emails[i].length <= 100
  • 1 <= emails.length <= 100
  • Each emails[i] contains exactly one '@' character.
  • All local and domain names are non-empty.
  • Local names do not start with a '+' character.
    題意:每封電子郵件都由一個(gè)本地名稱和一個(gè)域名組成,以 @ 符號(hào)分隔。里面可能包含‘+’和‘.’ 第一個(gè)‘+’后面的內(nèi)容會(huì)被忽略‘.’ 不影響蓉坎,求一共有多少電子郵件
    思路:按照題目要求飞袋,過濾扣泊,最后用set去重搞糕,輸出個(gè)數(shù)脊髓。
class Solution {
public:
    int numUniqueEmails(vector<string>& emails) {
        unordered_set<string> hash;
        for(auto email:emails)
        {
            int at=email.find('@');
            string name;
            for(auto c:email.substr(0,at))
                if(c=='+')
                    break;
            else if(c!='.')
                name+=c;
            string domain=email.substr(at+1);
            hash.insert(name+'@'+domain);
    
        }
        return hash.size();
    }
};
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末肉康,一起剝皮案震驚了整個(gè)濱河市闯估,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌吼和,老刑警劉巖涨薪,帶你破解...
    沈念sama閱讀 219,039評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異炫乓,居然都是意外死亡刚夺,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,426評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門末捣,熙熙樓的掌柜王于貴愁眉苦臉地迎上來侠姑,“玉大人,你說我怎么就攤上這事箩做∶Ш欤” “怎么了?”我有些...
    開封第一講書人閱讀 165,417評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)安吁。 經(jīng)常有香客問我醉蚁,道長(zhǎng),這世上最難降的妖魔是什么鬼店? 我笑而不...
    開封第一講書人閱讀 58,868評(píng)論 1 295
  • 正文 為了忘掉前任网棍,我火速辦了婚禮,結(jié)果婚禮上妇智,老公的妹妹穿的比我還像新娘滥玷。我一直安慰自己,他們只是感情好巍棱,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,892評(píng)論 6 392
  • 文/花漫 我一把揭開白布惑畴。 她就那樣靜靜地躺著,像睡著了一般航徙。 火紅的嫁衣襯著肌膚如雪桨菜。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,692評(píng)論 1 305
  • 那天捉偏,我揣著相機(jī)與錄音,去河邊找鬼泻红。 笑死夭禽,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的谊路。 我是一名探鬼主播讹躯,決...
    沈念sama閱讀 40,416評(píng)論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼缠劝!你這毒婦竟也來了潮梯?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,326評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤惨恭,失蹤者是張志新(化名)和其女友劉穎秉馏,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體脱羡,經(jīng)...
    沈念sama閱讀 45,782評(píng)論 1 316
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡萝究,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,957評(píng)論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了锉罐。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片帆竹。...
    茶點(diǎn)故事閱讀 40,102評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖脓规,靈堂內(nèi)的尸體忽然破棺而出栽连,到底是詐尸還是另有隱情,我是刑警寧澤侨舆,帶...
    沈念sama閱讀 35,790評(píng)論 5 346
  • 正文 年R本政府宣布秒紧,位于F島的核電站绢陌,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏噩茄。R本人自食惡果不足惜下面,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,442評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望绩聘。 院中可真熱鬧沥割,春花似錦、人聲如沸凿菩。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,996評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽衅谷。三九已至椒拗,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間获黔,已是汗流浹背蚀苛。 一陣腳步聲響...
    開封第一講書人閱讀 33,113評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留玷氏,地道東北人堵未。 一個(gè)月前我還...
    沈念sama閱讀 48,332評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像盏触,于是被迫代替她去往敵國(guó)和親渗蟹。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,044評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容