Leetcode - Angle Between Hands of a Clock
Leetcode - Minimum Increment to Make Array Unique

Leetcode - Unique Email Addresses

violet posted @ Jul 15, 2020 02:33:33 AM in 算法 with tags Algorithm Golang string , 572 阅读

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

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

For example, in alice@leetcode.comalice 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

 

func numUniqueEmails(emails []string) int {    
    hash := map[string]int{}
    for _, email := range emails {
        strs := strings.Split(email, "@")
        user := strings.Split(strs[0], "+")[0]
        domain := strs[1]
        username := strings.Join(strings.Split(user, "."), "")
        hash[username+"@"+domain]++
    }
    return len(hash)
}
Jharkhand Matric Imp 说:
Aug 24, 2022 12:54:36 PM

JAC 10th Question Paper 2023 Download – Jharkhand Matric Important Question Paper 2023 PDF, The State of Jharkhand came into existence on the 15th of November,2000. An Act to establish the Jharkhand Academic Council was enacted by the Jharkhand State Legislature and assented to by the Governor of the State on 26-12-2003, Jharkhand Matric Important Question Paper 2023 PDF/a> which was known as Jharkhand Academic Council Act 02.7.2003.

How to Recharge FAST 说:
Nov 11, 2022 03:10:17 PM

India’s digital market has influenced different industries, such as the transport sector and the banking system. These ranks India among the top best and advanced countries in the world. The digital transformation helps transact cash online without physically handling money. How to Recharge FASTag Using PhonePe Today India’s National Highway Authority benefits from online payment services such as FASTag. Drivers can pay for their toll without stopping at every toll plaza.

Emma 说:
Nov 16, 2022 10:56:07 PM

Leetcode's "Unique Email Addresses" problem is a great example what causes gout of how to use a HashSet to keep track of unique elements. The key here is to normalize the email addresses by removing the . and + characters. This way, we can be sure that all duplicate email addresses will be correctly identified.

eshram card download 说:
Dec 19, 2022 05:35:27 PM

The Central Government Administers initiatives for the social and economic development of the country’s unorganised workers and labourers. The government has also made E Shram card download available to applicants as part of this effort, eshram card download allowing them to download their labour card after applying. Here we will share you with all of the important information about the Downloading process online.

हिंदीप्रश्नपत्र.com 说:
May 01, 2023 03:31:37 PM

Hindi Model Question Papers Bihar School 10th Exam Board BSEB, Bihar Board 10th Class Model Papers 2023 Matric Exam Pattern, BSEB Patna Board Matric 10th Model Papers 2023 Sample Questions, Bihar Board 10th Model Papers 2023 Download, हिंदीप्रश्नपत्र.com BSEB Matric Bihar matric model paper 2023 bseb 10th sample paper 2023, bihar board 10th model paper 2023 pdf, bihar board 10th class model test paper 2023, bseb matric previous sample paper class 10th bihar board model question paper, bseb matric model question paper 2023.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter