Leetcode Note: Go - Unique Email Addresses
Unique Email Addresses - LeetCode
https://leetcode.com/problems/unique-email-addresses/
- Go 言語で取り組んだメモ
回答
simple golang map solution using strings package - LeetCode Discuss
https://leetcode.com/problems/unique-email-addresses/discuss/315194/simple-golang-map-solution-using-strings-package
func numUniqueEmails(emails []string) int {
actualEmails := make(map[string]bool)
for _, email := range emails {
at := strings.Index(email, "@")
localname, domain := email[:at], email[at:]
if plus := strings.Index(localname, "+"); plus != -1 {
localname = email[:plus]
}
localname = strings.Join(strings.Split(localname, "."), "")
actualEmails[localname + domain] = true
}
return len(actualEmails)
}