LeetCode - 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? 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
Hash
class Solution {
public int numUniqueEmails(String[] emails) {
if(emails == null || emails.length == 0){
return 0;
}
Set<String> set = new HashSet<>();
for(String email : emails){
String[] strs = email.split("@");
String localName = strs[0];
String domainName = strs[1];
StringBuilder sb = new StringBuilder();
for(char c : localName.toCharArray()){
if(c == '.'){
continue;
}
else if(c == '+'){
break;
}
else{
sb.append(c);
}
}
set.add(sb.toString() + "@" + domainName);
}
return set.size();
}
}
LeetCode - Unique Email Addresses的更多相关文章
- [leetcode] 929. Unique Email Addresses (easy)
统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...
- 929. Unique Email Addresses
929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...
- 【Leetcode_easy】929. Unique Email Addresses
problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...
- [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 929 Unique Email Addresses 解题报告
题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...
- 108th LeetCode Weekly Contest 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, ...
- [LeetCode] 929. Unique Email Addresses 独特的邮件地址
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
随机推荐
- Learning-Python【22】:面向对象初识
一.面向过程:是一种编程思想,核心是过程二字,过程指的是解决问题的步骤,即先干什么再干什么然后干什么,基于该编程思想写程序就好比在设计一条流水线,是一种机械式的思维方式 优点:把复杂问题流程化,进而简 ...
- JxBrowser之三:常用函数setNetworkDelegate
1.常用函数setNetworkDelegate,包含对网络传输数据状态的多种监控回调. 2.着重说一下其中的几个函数 BrowserContext browserContext = BrowserC ...
- js时间戳转化成日期格式
function timestampToTime(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的 ...
- Caused by: java.lang.NoClassDefFoundError: com/google/common/base/MoreObjects
环境:jdk1.8 开发工具:IDEA 说明:今天在做springboot集成swagger2的时候,在启动程序的时候,报错 报错信息: Error starting ApplicationConte ...
- codeforces 343d
题意:一棵树结构上有水,往一个节点加水,那么所有的子节点都会有水,或者排干一个节点的水,那么它的上面的节点都会没水. 用dfs序,数组记录区间内全部有水为1,区间内有没水的点就为0. 倒水:区间更新, ...
- webpack简单修改版本号(单页面)
写了一个js文件,可以尽量最简单的修改版本号 package.json配置: updateV.js放置位置: updateV.js: var fs = require('fs'); //文件读写 va ...
- 团队作业8——敏捷冲刺(Beta阶段)
Beta阶段--第1篇 Scrum 冲刺博客(计划) https://www.cnblogs.com/just-let-it-go/p/9061664.html Beta阶段--第2篇 Scrum 冲 ...
- 在react/redux中使用Immutable
在redux中使用Immutable 1.什么是Immutable? Immutable是一旦创建,就不能被更改的数据. 对Immutable对象的任何修改或添加删除操作都会返回一个新的Immutab ...
- 错误:Bean property 'sessionFactory' is not writable or has an invalid setter method.
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' ...
- codeblock不能调试
问题:codeblock 不能调试,如下图: 解决方法: 首先,项目的保存路径不能是中文路径. 其次,必须创建工程. 最后,build选项里select target选成debug codebloc ...