Problem
Every email consists of a local name and a domain name, separated by the @ sign.
For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name.
Besides lowercase letters, these emails may contain "."s or "+"s.
If you add periods (".") between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address. (Note that this rule does not apply for domain names.)
If you add a plus ("+") in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered, for example m.y+name@email.com will be forwarded to my@email.com. (Again, this rule does not apply for domain names.)
It is possible to use both of these rules at the same time.
Given a list of emails, we send one email to each address in the list. How many different addresses actually receive mails?
Example 1:
Input: ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]
Output: 2
Explanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails
Note:
1 <= emails[i].length <= 100
1 <= emails.length <= 100
Each emails[i] contains exactly one "@" character.
class Solution { public int numUniqueEmails(String[] emails) { Setset = new HashSet<>(); for (String email: emails) { String[] parts = email.split("@"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < parts[0].length(); i++) { char ch = parts[0].charAt(i); if (ch == ".") continue; else if (ch == "+") break; else sb.append(ch); } sb.append("@").append(parts[1]); set.add(sb.toString()); } return set.size(); } }
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/72519.html
摘要:题目链接题目分析题目要求过滤重复的邮箱地址。最终返回不重复的用户名个数。域名部分则不进行处理。替换为空字符串。下标为用户名部分,下标为域名部分删去后面的所有字符。最后,用包住以上代码,在外面初始化数组,用去重,再该数组就完成了。 929. Unique Email Addresses 题目链接 929. Unique Email Addresses 题目分析 题目要求过滤重复的邮箱地址...
摘要:前言的第一题独特的电子邮件地址每封电子邮件都由一个本地名称和一个域名组成,以符号分隔。例如,和会转发到同一电子邮件地址。实现代码独特的电子邮件地址本地名称域名根据指定规则解析后的本地名称,先按加号切割字符串,然后替换使用去重 前言 Weekly Contest 108的第一题 独特的电子邮件地址: 每封电子邮件都由一个本地名称和一个域名组成,以@符号分隔。 例如,在 alice@le...
摘要:题目初始算法测试提交优化算法利用的去重利用正则和是一个特殊字符所以需要转义符代表在之后的所有字符代表结尾代表或代表在全局用替代开始到结尾的字符和 1.题目Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, ...
摘要:因为是工作在一个内部,有时候我们可能不小心做了一些误删除的操作,可以回滚。我们先修改的用户名为,然后重新添加一个新,但是记住这个时候我们还没有。集合类型可以是各种合法类型,比如,但是默认集合是一个。 官方文档 Initialization # 检查是否已经安装以及版本号 >>> import sqlalchemy >>> sqlalchemy.__version__ ’1.1.4‘ ...
阅读 1711·2021-11-22 12:09
阅读 1451·2019-08-30 13:22
阅读 2082·2019-08-29 17:00
阅读 2634·2019-08-29 16:28
阅读 2945·2019-08-26 13:51
阅读 1174·2019-08-26 13:25
阅读 3236·2019-08-26 12:14
阅读 3006·2019-08-26 12:14