leetcode929

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode929相关的知识,希望对你有一定的参考价值。

package main

import (
    "fmt"
    "strings"
)

func numUniqueEmails(emails []string) int {
    var dic map[string]int
    dic = make(map[string]int)
    for _, s := range emails {
        strArr := strings.Split(s, "@")
        localname := strArr[0]
        domainname := strArr[1]
        plusIndex := strings.Index(localname, "+")
        if plusIndex > 0 {
            localname = localname[0:plusIndex]
        }
        localname = strings.Replace(localname, ".", "", -1)
        realmail := localname + "@" + domainname
        _, ok := dic[realmail]
        if ok {
            //found realmail
        } else {
            dic[realmail] = 1
        }
    }
    return len(dic)
}

func main() {
    emails := []string{"[email protected]", "[email protected]", "[email protected]"}
    num := numUniqueEmails(emails)
    fmt.Println(num)
}

 

以上是关于leetcode929的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 929 Unique Email Addresses 解题报告

[LeetCode] 929. Unique Email Addresses 独特的邮件地址

Leetcode 929. Unique Email Addresses

LeetCode --- 929. Unique Email Addresses 解题报告

Python描述 LeetCode 929. 独特的电子邮件地址

[leetcode] 929. Unique Email Addresses (easy)