码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode929

时间:2018-10-28 22:00:32      阅读:157      评论:0      收藏:0      [点我收藏+]

标签: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)
}

 

leetcode929

标签:make   leetcode   turn   dom   unique   .com   class   uniq   domain   

原文地址:https://www.cnblogs.com/asenyang/p/9867158.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!