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

資訊專欄INFORMATION COLUMN

1.過濾郵箱地址

caiyongji / 698人閱讀

摘要:題目初始算法測試提交優化算法利用的去重利用正則和是一個特殊字符所以需要轉義符代表在之后的所有字符代表結尾代表或代表在全局用替代開始到結尾的字符和

1.題目
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:
    def numUniqueEmails(self, emails: List[str]) -> int:
        n = len(emails)
        final_list = []
        for i in range(0, n):
            split_list =  emails[i].split("@")
            local_name, domain_name = split_list[0].split("."), split_list[1]
            local_name = "".join(local_name).split("+")[0]
            final_name = local_name + "@" + domain_name
            if(final_name not in final_list):
                final_list.append(final_name)        
        return len(final_list)
測試提交 Runtime: 52 ms, faster than 55.04% of Python3 online submissions
for Unique Email Addresses. Memory Usage: 13.2 MB, less than 5.79% of
Python3 online submissions for Unique Email Addresses.

優化算法

利用python的set去重

class Solution:
    def numUniqueEmails(self, emails):
        """
        :type emails: List[str]
        :rtype: int
        """
        email_set = set()
        for email in emails:
            local_name,domain_name = email.split("@")
            local_name ="".join(local_name.split("+")[0].split("."))
            email = local_name +"@" + domain_name
            email_set.add(email)
        return len(email_set)

Js利用正則和Set

const numUniqueEmails = emails => new Set(emails.map(mail => `${mail.split("@")[0].replace(/+.*$|./g, "")}@${mail.split("@")[1]}`)).size

is a specail char, so adds .

.* means any character after +.
$, in regex, it represents the end of string.
| equals to or.
. is also a special char, so adds .
In the end of regex, g, global search, means finding all matches in input and replace them.
In sum, replace the substring that after sign + or the char . with empty string.

1.+是一個特殊字符所以需要轉義符
2..*代表在+之后的所有字符
3.$代表結尾
4.|代表或
5.replace(/+.*$|./g, "")代表在全局用""替代+開始到結尾的字符和.

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/102956.html

相關文章

  • 1.過濾郵箱地址

    摘要:題目初始算法測試提交優化算法利用的去重利用正則和是一個特殊字符所以需要轉義符代表在之后的所有字符代表結尾代表或代表在全局用替代開始到結尾的字符和 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
  • Leetcode PHP題解--D2 929. Unique Email Addresses

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

    xuhong 評論0 收藏0
  • 登陸郵箱主機名什么意思-蘋果qq郵箱收件服務器主機名填什么?

    摘要:蘋果郵箱收件服務器主機名填什么您好,如果是給手機設置郵箱。符號的左側是對方的登錄名,右側是完整的主機名,由主機名和域名組成。其中,域名由幾個部分組成,每個部分稱為一個子域,子域之間用圓點隔開,每個子域將告訴用戶一些有關該郵件服務器的信息。蘋果qq郵箱收件服務器主機名填什么?您好,如果是給手機設置郵箱。您使用手機郵箱客戶端之前,請確保您是否開通了imapsmtppop3郵箱服務,如果沒有請到網...

    SegmentFault 評論0 收藏0
  • 收件服務器主機名應該填寫什么-郵件主機名該如何填寫?

    摘要:協議接收郵件服務器,使用,端口號。發送郵件服務器,使用,端口號蘋果郵箱收件服務器主機名填什么您好,如果是給手機設置郵箱。郵箱的服務器端口號為,收件服務器端口號是,發件服務器端口號是最后點擊完成。郵件主機名該如何填寫?以qq為例,收件服務器為imap.qq.com,發件服務器為smtp.qq.com,具體如下:1.在郵箱中啟用IMAP服務。 在Mail中創建一個新的QQ郵箱賬戶,單擊手動設置進...

    habren 評論0 收藏0

發表評論

0條評論

caiyongji

|高級講師

TA的文章

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