Lever's Castle

929. 独特的电子邮件地址

December 25, 2018

https://leetcode-cn.com/problems/unique-email-addresses/

使用语言:Golang

func numUniqueEmails(emails []string) int {
    m := make(map[string]int)
    for _, email := range emails {
        result := strings.Split(email, "@")
        before := result[0]
        after := result[1]
        result = strings.Split(before, "+")
        before = result[0]
        before = strings.Replace(before, ".", "", -1)
        m[before + "@" + after] = 1
    }
    
    return len(m)
}

本周随机出来的题比较简单,直接构造了一个 map 来存放实际的 email,也顺便避免了去重的问题。主要熟悉了一下 Golang 的 SplitReplace 以及 Index 函数。

函数的类型声明如下:

func Split(s, sep string) []string
// n 表示替换前几个匹配到的字符串,n 为 -1 时,没有数量限制
func Replace(s, old, new string, n int) string
func Index(s, substr string) int

Lever

痕迹
没有过去,就没法认定现在的自己