leetcode929
package main import (
"fmt"
"strings"
) func numUniqueEmails(emails []string) int {
var dic map[string]int
dic = make(map[string]int)
for _, s := range emails {
strArr := strings.Split(s, "@")
localname := strArr[]
domainname := strArr[]
plusIndex := strings.Index(localname, "+")
if plusIndex > {
localname = localname[:plusIndex]
}
localname = strings.Replace(localname, ".", "", -)
realmail := localname + "@" + domainname
_, ok := dic[realmail]
if ok {
//found realmail
} else {
dic[realmail] =
}
}
return len(dic)
} func main() {
emails := []string{"test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"}
num := numUniqueEmails(emails)
fmt.Println(num)
}
public class Solution
{
public int NumUniqueEmails(string[] emails)
{
var dic = new Dictionary<string, int>();
foreach (var email in emails)
{
var mails = email.Split('@');
var localname = mails[];
var domainname = mails[]; var plusIndex = localname.IndexOf('+');
if (plusIndex >= )
{
localname = localname.Substring(, plusIndex);
}
localname = localname.Replace(".", "");
var realmail = localname + "@" + domainname; if (!dic.ContainsKey(realmail))
{
dic.Add(realmail, );
}
}
return dic.Count;
}
}
leetcode929的更多相关文章
- [Swift]LeetCode929. 独特的电子邮件地址 | Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
- Leetcode929.Unique Email Addresses独特的电子邮件地址
每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母,这些电 ...
- leetcode929 Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
随机推荐
- MySQL--常见ALTER TABLE 操作
##================================## ## 修改表的存储引擎 ## SHOW TABLE STATUS LIKE 'TB_001' \G; ALTER TABLE ...
- WebApi_基于Token的身份验证——JWT
JWT是啥? JWT就是一个字符串,经过加密处理与校验处理的字符串,形式为: A.B.C A由JWT头部信息header加密得到B由JWT用到的身份验证信息json数据加密得到C由A和B加密得到,是校 ...
- FP-growth算法发现频繁项集(一)——构建FP树
常见的挖掘频繁项集算法有两类,一类是Apriori算法,另一类是FP-growth.Apriori通过不断的构造候选集.筛选候选集挖掘出频繁项集,需要多次扫描原始数据,当原始数据较大时,磁盘I/O次数 ...
- Sqoop之 Sqoop 1.4.6 安装
1. sqoop数据迁移 1.1 概述 sqoop是apache旗下一款“Hadoop和关系数据库服务器之间传送数据”的工具. 导入数据:MySQL,Oracle导入数据到Hadoop的HDFS.HI ...
- Maven的dependency scope属性
官方地址:https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependen ...
- Apache Derby数据库 安装、知识点
Apache Derby数据库 安装: 下载路径:http://archive.apache.org/dist/db/derby/ 出处:http://www.yiibai.com/hive/hive ...
- hadoop 安装、命令
hadoop安装步骤: 安装java 安装hadoop 下载地址:http://apache.claz.org/hadoop/common/ (说明:该网址current文件夹下,是最新版) hado ...
- DBLinq (MySQL exactly) Linq To MySql
http://blog.csdn.net/feihu_guest/article/details/7346948 DBLinq (MySQL exactly) Linq To MySql http:/ ...
- python 典型文件结构
#/usr/bin/env/ python #(1) 起始行 "this is a test module" #(2) 模块文档(文档字符串) import sys import ...
- 【python】网络编程-SocketServer 实现客户端与服务器间非阻塞通信
利用SocketServer模块来实现网络客户端与服务器并发连接非阻塞通信.首先,先了解下SocketServer模块中可供使用的类:BaseServer:包含服务器的核心功能与混合(mix-in)类 ...