Open Zheaoli opened 2 years ago
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
/*
* @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 插件
2022-06-04