首页 > 其他 > 详细

leetcode929

时间:2018-10-28 21:17:58      阅读:197      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!