Question

929. Unique Email Address

Solution

题目大意:

给你一个邮箱地址的数组,求出有多少个不同的地址,其中localName有如下规则

  1. 加号(+)后面的字符及加号忽略
  2. 点(.)也忽略

思路:

直接遍历,字符串操作即可

Java实现:

public int numUniqueEmails(String[] emails) {
if (emails == null || emails.length == 0) {
return 0;
} Set<String> localNames = new HashSet<>();
for (String email : emails) {
String[] arr = email.split("@");
String localName = arr[0];
// 忽略加号(+)后边的字符
int indexOfPlus = localName.indexOf("+");
if (indexOfPlus != -1) {
localName = localName.substring(0, indexOfPlus);
}
// 替换逗号
localName = localName.replaceAll("\\.", "");
localNames.add(localName + "@" + arr[1]);
}
return localNames.size();
}

在处理地址的时候,用下面的方法取localName和domainName更快

int indexOfAt = email.indexOf("@");
String localName = email.substring(0, indexOfAt);
String domainName = email.substring(indexOfAt);

929. Unique Email Address - LeetCode的更多相关文章

  1. 929. Unique Email Addresses

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

  2. 【Leetcode_easy】929. Unique Email Addresses

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

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

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

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

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

  5. LeetCode 929.Unique Email Addresses

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

  6. LeetCode 929 Unique Email Addresses 解题报告

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

  7. 【leetcode】929. Unique Email Addresses

    题目如下: Every email consists of a local name and a domain name, separated by the @ sign. For example, ...

  8. 【LeetCode】929. Unique Email Addresses 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set + 字符串操作 参考资料 日期 题目地址:h ...

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

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

随机推荐

  1. Java设置方法模板

  2. CommonCollection1反序列化学系

    CommonsCollection1 1.前置知识 1.1.反射基础知识 1.1.1. 对象与类的基础知识 类(class),对象(object) 对象是类的实例化,中华田园犬(object)是狗(c ...

  3. 《每周一点canvas动画》——3D点线与水波动画

    <每周一点canvas动画>--差分函数的妙用 每周一点canvas动画代码文件 好像上次更新还是十一前,这唰唰唰的就过去大半个月了,现在才更新实在不好意思.这次我们不涉及canvas 3 ...

  4. PAT B1013 数素数

    输入样例: 5 27   输出样例: 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 解题思路: 从2开始 ...

  5. 写入MySQL中文乱码问题

    相信使用数据库进行存储的大家都遇到过中文乱码问题,如何彻底解决?我百度了很多资料与博客,想把自己的经历总结起来给大家参考一下,接下来我先罗列一下大部分修改乱码问题的方法: 1.   修改MySQL数据 ...

  6. 【UWP】实现一个波浪进度条

    好久没写 blog 了,一个是忙,另外一个是觉得没啥好写.废话不多说,直接上效果图: 可能看到这波浪线你觉得会很难,但看完这篇 blog 后应该你也会像我一样恍然大悟.图上的图形,我们可以考虑是由 3 ...

  7. SpringMVC-设置编码过滤器

    1.接上文->springmvc获取请求参数链接 2.在web.xml配置编码过滤器 <!-- 配置编码过滤器--> <filter> <filter-name&g ...

  8. String相关API-getBean()方法的使用

    一.使用id //userService是Bean标签中配置的id属性值 UserService service = (UserService) context.getBean("userS ...

  9. LC-1

    Two Sum Given an array of integers nums and an integer target, return indices of the two numbers suc ...

  10. linux ping的三个数字(56,84,64)

    参考:ping 深入剖析:https://www.cnblogs.com/aozhejin/p/15917312.html windows默认是32字节,linux是56字节说的都是数据包大小注意:1 ...