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[]
domainname := strArr[]
plusIndex := strings.Index(localname, "+")
if plusIndex > {
localname = localname[:plusIndex]
}
localname = strings.Replace(localname, ".", "", -)
realmail := localname + "@" + domainname
_, ok := dic[realmail]
if ok {
//found realmail
} else {
dic[realmail] =
}
}
return len(dic)
} func main() {
emails := []string{"[email protected]", "[email protected]", "[email protected]"}
num := numUniqueEmails(emails)
fmt.Println(num)
}
public class Solution
{
public int NumUniqueEmails(string[] emails)
{
var dic = new Dictionary<string, int>();
foreach (var email in emails)
{
var mails = email.Split('@');
var localname = mails[];
var domainname = mails[]; var plusIndex = localname.IndexOf('+');
if (plusIndex >= )
{
localname = localname.Substring(, plusIndex);
}
localname = localname.Replace(".", "");
var realmail = localname + "@" + domainname; if (!dic.ContainsKey(realmail))
{
dic.Add(realmail, );
}
}
return dic.Count;
}
}
04-19 21:14