leetcode929 Unique Email Addresses
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?
每封电子邮件由一个本地名称和一个域名组成,以@符号分隔。
例如,在alice@leetcode.com中,alice是本地名,leetcode.com是域名。
除了小写字母,这些邮件还可能包含' '。”或“+”。
如果您在电子邮件地址的本地名称部分的某些字符之间添加句点('.'),那么发送到那里的邮件将被转发到相同的地址,而本地名称中没有点号。例如,“alice.z@leetcode.com”和“alicez@leetcode.com”转发到相同的电子邮件地址。(请注意,此规则不适用于域名。)
如果在本地名称中添加加号('+'),第一个加号后面的所有内容都将被忽略。这允许某些电子邮件被过滤,例如m.y+name@email.com将被转发到my@email.com。(同样,这条规则不适用于域名。)
同时使用这两个规则是可能的。
给定一个电子邮件列表,我们向列表中的每个地址发送一封电子邮件。有多少不同的地址实际接收邮件?
class Solution {
public int numUniqueEmails(String[] emails) {
Set<String> hs=new HashSet();
for(String s:emails)
{
int count1=s.indexOf('@');
String local=s.substring(0,count1);
String rest=s.substring(count1);
if(local.contains("+")){
local=local.substring(0,local.indexOf('+'));
}
local=local.replaceAll(".","");
s=local+rest;
hs.add(s);
}
return hs.size();
}
}
leetcode929 Unique Email Addresses的更多相关文章
- Leetcode929.Unique Email Addresses独特的电子邮件地址
每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母,这些电 ...
- 929. Unique Email Addresses
929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...
- [leetcode] 929. Unique Email Addresses (easy)
统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...
- 【Leetcode_easy】929. Unique Email Addresses
problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...
- [Swift]LeetCode929. 独特的电子邮件地址 | Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
- [LeetCode] 929. Unique Email Addresses 唯一的电邮地址
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
- LeetCode 929.Unique Email Addresses
Description Every email consists of a local name and a domain name, separated by the @ sign. For exa ...
- LeetCode - Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
- LeetCode 929 Unique Email Addresses 解题报告
题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...
随机推荐
- linux 扩展内存
一.逻辑卷创建使用 https://www.cnblogs.com/xiaoluo501395377/archive/2013/05/24/3096087.html fdisk -l pvcreate ...
- GitBook相关使用以及配置笔记
本地安装 GitBook的安装非常简单.您的系统只需满足这两个要求: NodeJS(推荐使用v4.0.0及以上版本) Windows,Linux,Unix或Mac OS X gitbook-cli 是 ...
- linux上安装git以及使用
用git --version命令检查是否已经安装 在CentOS5的版本,由于yum源中没有git,所以需要预先安装一系列的依赖包.在CentOS6的yum源中已经有git的版本了,可以直接使用yum ...
- IntelliJ IDEA 2017.3-----导入jar包
1.选择jar包 2.右键选择 3.点击ok
- C++-POJ1020-Anniversary Cake[搜索][dfs]
#include <set> #include <map> #include <cmath> #include <queue> #include < ...
- 修正_typora文档复制到博客图片失效
开始 今天开始尝试使用 Typora 写markdown 然后复制到博客园,不过会有一个问题 那就是 typroa 插入的图片都是本地的,md文档复制到博客园之后,图片都失效了 通过百度,有工具可以直 ...
- 使用VS2015调试Qt5.9.5源码
调试的前提 1.Qt5.9.5源码. 2.Qt5.9.5对应VS2015版本的pdb文件. 前提1在安装Qt时勾选源代码选项即可,这样安装后的Qt目录会多出一个“Src”的目录,里面就是Qt的源码. ...
- SaltStack自动化软件简介及安装
==================================================================================================== ...
- Pandas数据结构(一)——Pandas Series
Pandas 是 Python 中基于Numpy构建的数据操纵和分析软件包,包含使数据分析工作变得快速简洁的高级数据结构和操作工具.通过Pandas Series 和 Pandas DataFrame ...
- 解析python 生产/消费者模型实现过程
1.多线程实现 import threadingimport queueimport logginglogging.basicConfig(level = logging.INFO,format = ...