国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[LeetCode] 929. Unique Email Addresses

amuqiao / 1144人閱讀

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.

Solution
class Solution {
    public int numUniqueEmails(String[] emails) {
        Set set = 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

相關(guān)文章

  • Leetcode PHP題解--D2 929. Unique Email Addresses

    摘要:題目鏈接題目分析題目要求過濾重復(fù)的郵箱地址。最終返回不重復(fù)的用戶名個數(shù)。域名部分則不進(jìn)行處理。替換為空字符串。下標(biāo)為用戶名部分,下標(biāo)為域名部分刪去后面的所有字符。最后,用包住以上代碼,在外面初始化數(shù)組,用去重,再該數(shù)組就完成了。 929. Unique Email Addresses 題目鏈接 929. Unique Email Addresses 題目分析 題目要求過濾重復(fù)的郵箱地址...

    xuhong 評論0 收藏0
  • 929-獨(dú)特的電子郵件地址

    摘要:前言的第一題獨(dú)特的電子郵件地址每封電子郵件都由一個本地名稱和一個域名組成,以符號分隔。例如,和會轉(zhuǎn)發(fā)到同一電子郵件地址。實(shí)現(xiàn)代碼獨(dú)特的電子郵件地址本地名稱域名根據(jù)指定規(guī)則解析后的本地名稱,先按加號切割字符串,然后替換使用去重 前言 Weekly Contest 108的第一題 獨(dú)特的電子郵件地址: 每封電子郵件都由一個本地名稱和一個域名組成,以@符號分隔。 例如,在 alice@le...

    IntMain 評論0 收藏0
  • 1.過濾郵箱地址

    摘要:題目初始算法測試提交優(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, ...

    caiyongji 評論0 收藏0
  • 1.過濾郵箱地址

    摘要:題目初始算法測試提交優(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, ...

    littleGrow 評論0 收藏0
  • Python-SQLALchemy

    摘要:因?yàn)槭枪ぷ髟谝粋€內(nèi)部,有時候我們可能不小心做了一些誤刪除的操作,可以回滾。我們先修改的用戶名為,然后重新添加一個新,但是記住這個時候我們還沒有。集合類型可以是各種合法類型,比如,但是默認(rèn)集合是一個。 官方文檔 Initialization # 檢查是否已經(jīng)安裝以及版本號 >>> import sqlalchemy >>> sqlalchemy.__version__ ’1.1.4‘ ...

    kumfo 評論0 收藏0

發(fā)表評論

0條評論

amuqiao

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<