标签:make leetcode turn dom unique .com class uniq domain
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{"test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"} num := numUniqueEmails(emails) fmt.Println(num) }
标签:make leetcode turn dom unique .com class uniq domain
原文地址:https://www.cnblogs.com/asenyang/p/9867158.html