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的更多相关文章

  1. [Swift]LeetCode929. 独特的电子邮件地址 | Unique Email Addresses

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

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

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

  3. leetcode929 Unique Email Addresses

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

随机推荐

  1. 《DSP using MATLAB》Problem 3.6

    逆DTFT定义如下: 需要求积分,

  2. js 时间操作积累

    console.log( new Date() ); //Tue Mar 20 2018 22:47:01 GMT+0800 (中国标准时间) // var date = new Date( '201 ...

  3. UVA11525 【Permutation】

    分析 简述"康托展开" 康托展开是一个全排列到一个自然数的双射,常用于构建hash表时的空间压缩.设有\(n\)个数\((1,2,3,4,-,n)\),可以有组成不同(\(n!\) ...

  4. adnanh webhook 框架使用

    adnanh webhook 支持以下功能: 接收请求 解析header 以及负载以及查询变量 规则检查 执行命令 简单测试 使用docker-compose docker-compose 文件 ve ...

  5. ThinkPHP5 控制器中怎么实现 where id = 2 or id = 3 这个查询语句?

    使用 whereOr whereIn();  (来自 ★C̶r̶a̶y̶o̶n-杭州 ) 为什么不用数组啊,array('eq', array(1,2),'or') (来自 supler)

  6. 【转】每天一个linux命令(11):nl命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/11/01/2749048.html nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件 ...

  7. Mono.Cecil 修改目标.NET的IL代码保存时报异常的处理。

    使用Mono.Cecil对目标.NET的DLL程序进行IL修改后保存时报“Failed to resolve assembly: ' xxxxxx, version=xxxxx,Culture=xxx ...

  8. phonegap 2.9 IOS Xcode 搭建环境

    一:下载phoneGap2.9和安装Xcode5(目前最新版) 选择2.9是因为3.0以上坑爹版本编译神马的要在有网络情况. 二: 下载phonegap后解压到你的指定文件夹中,解压后找到create ...

  9. springMVC学习(6)-包装pojo类型、数组、list、Map类型参数绑定

    一.包装类型pojo参数绑定: 需求:商品查询controller方法中实现商品查询条件传入. 实现方法: 1)在形参中 添加HttpServletRequest request参数,通过reques ...

  10. Android手机卸载第三方应用

    测试机互相拆借,过多的应用占用手机空间,使用脚本将不需要的第三方应用卸载. #!/bin/sh #白名单 whiteName=( com.tencent.mobileqq com.tencent.mm ...