题目标签:String

  题目说明 有两个规则针对于 local name。 所以先把local name 和 domain name 分开。

  两个规则是:

    rule 1:'.' 会被去除。 (利用replace 把 '.' 换成 '')

    rule 2:'+' 之后的所有东西都会被 去除。(利用substring 把 '+' 之后的去除)

Java Solution:

Runtime beats 34.05%

完成日期:12/08/2018

关键点:substring 和 replace

class Solution
{
public int numUniqueEmails(String[] emails)
{
Set<String> set = new HashSet<>(); for(String email : emails)
{
String editedEmail = editEmail(email); set.add(editedEmail); } return set.size();
} private String editEmail(String email)
{
int index = email.indexOf('@');
String str_1 = email.substring(0, index);
String str_2 = email.substring(index); if(str_1.contains("+"))
str_1 = str_1.substring(0, str_1.indexOf('+')); str_1 = str_1.replace(".", ""); return str_1 + str_2;
}
}

参考资料:N/A

LeetCode 题目列表 - LeetCode Questions List

题目来源:https://leetcode.com/

LeetCode 929. Unique Email Addresses (独特的电子邮件地址)的更多相关文章

  1. 【LeetCode】Unique Email Addresses(独特的电子邮件地址)

    这道题是LeetCode里的第929道题. 题目要求: 每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而  ...

  2. [LeetCode] 929. Unique Email Addresses 独特的邮件地址

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  3. Leetcode929.Unique Email Addresses独特的电子邮件地址

    每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母,这些电 ...

  4. [leetcode] 929. Unique Email Addresses (easy)

    统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...

  5. [LeetCode] 929. Unique Email Addresses 唯一的电邮地址

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  6. LeetCode 929.Unique Email Addresses

    Description Every email consists of a local name and a domain name, separated by the @ sign. For exa ...

  7. LeetCode 929 Unique Email Addresses 解题报告

    题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...

  8. 929. Unique Email Addresses

    929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...

  9. 【Leetcode_easy】929. Unique Email Addresses

    problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...

随机推荐

  1. axios 正确打开方式

    一.安装1. 利用npm安装npm install axios --save2. 利用bower安装bower install axios --save3. 直接利用cdn引入<script s ...

  2. java byte

    项目中有段代码,一直让我疑惑不解,但我是个很会偷懒的人,只要拷贝来改改能用的代码,万万不会自己动手写,虽然一直有疑惑,也懒得搭理是怎么个原理. 直到今天,又要解析协议,又要动这个地方的代码,还是来盘他 ...

  3. CAD多个点构造选择集(网页版)

    主要用到函数说明: IMxDrawSelectionSet::SelectByPolygon 在多个点组合的闭合区域里,构造选择集.详细说明如下: 参数 说明 [in] IMxDrawPoints* ...

  4. java虚拟机(五)--垃圾回收机制GC5

    什么样的对象需要回收 如果对象已经死亡了,就可以进行回收,判断方式如下 1).引用计数器:给对象添加一个计数器,有地方引用,就+1,当引用失效,就-1.当计数器为0时,判断对象不能再使用,但是当对象相 ...

  5. 04Servlet的生命周期

    Servlet的生命周期 Servlet运行在Servlet容器中,其生命周期由容器来管理.Servlet的生命周期通过javax.servlet.Servlet接口中的init().service( ...

  6. Python常用的内建模块

    PS:Python之所以自称“batteries included”,就是因为内置了许多非常有用的模块,无需额外安装和配置,即可直接使用.下面就来看看一些常用的内建模块. 参考原文 廖雪峰常用的内建模 ...

  7. C++关键字:explicit

    #include "pch.h" #include <iostream> using namespace std; class BaseClass { public: ...

  8. linux more-显示文件内容,每次显示一屏

    博主推荐:获取更多 linux文件内容查看命令 收藏:linux命令大全 more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作.more名单中 ...

  9. Tornado进阶

    三.Tornado进阶 3.1 Application settings debug,设置tornado是否工作在调试模式,默认为False即工作在生产模式.当设置debug=True 后,torna ...

  10. 第七节:web爬虫之urllib(三)

    第二个模块 error : 即异常处理模块,如果出现请求错误,我们可以捕获这些异常,然后进行重试或其他操作保证程序不会意外终止.