Zheaoli / do-something-right

MIT License
37 stars 3 forks source link

2022-06-04 #258

Open Zheaoli opened 2 years ago

Zheaoli commented 2 years ago

2022-06-04

SaraadKun commented 2 years ago

929. 独特的电子邮件地址

class Solution {
    public int numUniqueEmails(String[] emails) {
        HashSet<String> set = new HashSet<>();
        for (String email : emails) {
            int idx = email.indexOf('@');
            String s1 = email.substring(0, idx).split("\\+")[0].replace(".", "");
            set.add(s1 + email.substring(idx));
        }
        return set.size();
    }
}

WeChat: Saraad

dreamhunter2333 commented 2 years ago
/*
 * @lc app=leetcode.cn id=929 lang=golang
 *
 * [929] 独特的电子邮件地址
 */

// @lc code=start
func numUniqueEmails(emails []string) int {
    cache := make(map[string]bool, 0)
    for _, email := range emails {
        res := strings.Split(email, "@")
        name := res[0]
        domain := res[1]
        name = strings.ReplaceAll(name, ".", "")
        if strings.Contains(name, "+") {
            name = name[:strings.Index(name, "+")]
        }
        cache[name+"@"+domain] = true
    }
    return len(cache)
}

// @lc code=end

微信id: 而我撑伞 来自 vscode 插件