Problem
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?
Example 1:
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.
class Solution { public int numUniqueEmails(String[] emails) { Setset = new HashSet<>(); for (String email: emails) { String[] parts = email.split("@"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < parts[0].length(); i++) { char ch = parts[0].charAt(i); if (ch == ".") continue; else if (ch == "+") break; else sb.append(ch); } sb.append("@").append(parts[1]); set.add(sb.toString()); } return set.size(); } }
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/72519.html
摘要:題目鏈接題目分析題目要求過濾重復(fù)的郵箱地址。最終返回不重復(fù)的用戶名個數(shù)。域名部分則不進(jìn)行處理。替換為空字符串。下標(biāo)為用戶名部分,下標(biāo)為域名部分刪去后面的所有字符。最后,用包住以上代碼,在外面初始化數(shù)組,用去重,再該數(shù)組就完成了。 929. Unique Email Addresses 題目鏈接 929. Unique Email Addresses 題目分析 題目要求過濾重復(fù)的郵箱地址...
摘要:前言的第一題獨(dú)特的電子郵件地址每封電子郵件都由一個本地名稱和一個域名組成,以符號分隔。例如,和會轉(zhuǎn)發(fā)到同一電子郵件地址。實(shí)現(xiàn)代碼獨(dú)特的電子郵件地址本地名稱域名根據(jù)指定規(guī)則解析后的本地名稱,先按加號切割字符串,然后替換使用去重 前言 Weekly Contest 108的第一題 獨(dú)特的電子郵件地址: 每封電子郵件都由一個本地名稱和一個域名組成,以@符號分隔。 例如,在 alice@le...
摘要:題目初始算法測試提交優(yōu)化算法利用的去重利用正則和是一個特殊字符所以需要轉(zhuǎn)義符代表在之后的所有字符代表結(jié)尾代表或代表在全局用替代開始到結(jié)尾的字符和 1.題目Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, ...
摘要:因?yàn)槭枪ぷ髟谝粋€內(nèi)部,有時候我們可能不小心做了一些誤刪除的操作,可以回滾。我們先修改的用戶名為,然后重新添加一個新,但是記住這個時候我們還沒有。集合類型可以是各種合法類型,比如,但是默認(rèn)集合是一個。 官方文檔 Initialization # 檢查是否已經(jīng)安裝以及版本號 >>> import sqlalchemy >>> sqlalchemy.__version__ ’1.1.4‘ ...
閱讀 1729·2021-11-22 12:09
閱讀 1459·2019-08-30 13:22
閱讀 2092·2019-08-29 17:00
閱讀 2642·2019-08-29 16:28
閱讀 2954·2019-08-26 13:51
閱讀 1181·2019-08-26 13:25
閱讀 3243·2019-08-26 12:14
閱讀 3014·2019-08-26 12:14