Unique Email Addresses

IBM DS存储Storage Manager客户端深度排错指南 IBM DS系列存储的Storage Manager客户端并非普通图形管理工具,而是基于SNMP与私有SOAP协议的底层设备通信代理,其运行高度依赖固件版本匹配、TCP/IP栈精准配置及SSL证书信任链。理解其作为嵌入式管理代理的原理,有助于规避因网络层不兼容、服务注册失败或证书未导入导致的连接中断。该技术方案广泛应用于金融、制造等行业的DS3500/DS5020等中端存储运维场景,支撑LUN映射、RAID重建与日志采集等关键任务。本文聚焦Windows环境下的服务化部署、端口监听验证与跨层连通性诊断,覆盖 阅读详情

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

Note:

1 <= emails[i].length <= 100
1 <= emails.length <= 100
Each emails[i] contains exactly one ‘@’ character.

问题剖析

上述问题本质上是对字符串的处理问题,需要用到字符串的分割,合并,替换等操作。难度本身不大,只是为了熟悉字符串操作而已。所以本人首先了一个效率不怎么高的解法,拆分字符串数组,对每个"邮箱地址"进行处理。代码如下所示:

func numUniqueEmails(emails []string) int {
    
    if emails == nil {
        return 0
    }
    
    actual := make([]string, 0)
    
    for _, email := range emails {
        
        local := strings.Split(email, "@")[0]
        domain := strings.Split(email, "@")[1]
        
        if strings.Index(local, "+") != -1 {
            local = strings.Split(local, "+")[0]
        }
        
        local = strings.Replace(local, ".", "", -1)
        
        newEmail := fmt.Sprintf("%s@%s", local, domain)
        
        if !isInActual(actual, newEmail) {
            actual = append(actual, newEmail)
        }
    }
    
    return len(actual)
}

func isInActual(actual []string, str string) bool {
    isIn := false
    
    for _, item := range actual {
        if item == str {
            isIn = true
        }
    }
    return isIn
}

这个解法虽然搞定了需求,但是有很多多余的操作,比如判断是否是重复的字符串的时候,其实没必要通过函数调用isInActual,去一次次的遍历整个列表。这样的操作是O(n^2)时间复杂度。而golang本身提供了map这样的数据结构可以去重,所以代码可以再次简化:

func numUniqueEmails(emails []string) int {
    
    if emails == nil {
        return 0
    }
    
    e_map := make(map[string]int)
    
    for idx, email := range emails {
        
        local  := strings.Split(email, "@")[0]
        domain := strings.Split(email, "@")[1]
        if strings.Index(local, "+") != -1 {
            local = strings.Split(local, "+")[0]
        }
        
        local = strings.Replace(local, ".", "", -1)
        
        newEmail := fmt.Sprintf("%s@%s", local, domain)
        
        if _, ok:= e_map[newEmail]; !ok {
            e_map[newEmail] = idx
        }
    }

    return len(e_map)
}

整个解法比上个解法整整快了一倍,时间比较如下:
在这里插入图片描述
欢迎大家进行改进,希望得到更快的解法。

leetcode上有个哥们用了比较复杂的表达式进行切分,也得到了结果。代码比较简短。但是可读性不太好,而且比我的第二个解法还慢了一些。代码示例如下:

func numUniqueEmails(emails []string) int {
	m := make(map[string]int)
	for i := 0; i < len(emails); i++ {
		parsedEmail := strings.Join(strings.Split(emails[i][0:strings.Index(emails[i], "+")-1], "."), "") + emails[i][strings.Index(emails[i], "@"):]
		if _, ok := m[parsedEmail]; ok {
			continue
		}
		m[parsedEmail] = i
	}
	result := len(m)
	return result
}
address list.zip VC6.0开发的一个字符界面的校友录程序,采用C++ 语言编写,数据存储于文本文档中。 校友录管理 总体需求 编写一个校友录管理软件 校友的信息包括姓名、性别、年龄、界级、系、班级、通讯地址、电话、qq、Email…… 功能需求 能够实现数据的录入、查询(按姓名、界级、系、班级)、修改、删除、排序(按姓名、界级)。 用户界面 输入: 程序正常运行后,屏幕上显示一个文字菜单(根据序号选定相应的操作项目),当用户选定操作项目所对应的序号时,根据应用程序的提示信息,从键盘上输入相应的数据。 输出: 1) 应用程序正常运行后,要在屏幕上显示一个文字菜单 2) 要求用户输入数据时,要给出清晰、明确的提示信息,包括输入的数据内容、格式及结束方式等 提示与参考 1)为各项操作功能设计一个菜单,应用程序运行后,先显示这个菜单,然后用户通过菜单项选择希望进行的操作项目。 2) 将校友的信息定义为一个结构体;每个人的编号应唯一,不可重复。 3)采用文件保存数据, 关于文件的读写方法请参见教材的“文件”章节。 立即下载

相关推荐

address adress

address address address address

LeetCode929 Unique Email Addresses(独特的电子邮件地址) C++实现

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 l...

帽帽的博客 5372

邮件管理系统C语言

Email address book includes two types of email address: General address, include information: email address (unique), name, phone number Group address, include information: email address (unique), name, list of address(each address may be a general address or a group address). Write an Email address book management program with C/C++ language: Give an email address, find its information. If given address is a group address, should list all the general addresses in this group. Add/Remove one email address. Read email address book from a source file. Save email address book to a destination file.

929. Unique Email Address

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...

PIG_CODE的博客 1016

FPGA之全数字锁相环(DPLL)

1. 数字锁相环的基本原理和组成 1.1 锁相环(PLL)的简介 锁相环最开始并不是用在数字电路中,而是模拟短路中。对于模拟电路中的锁相环,大家可以参考这篇文章稍微看一下,数字和模拟只是实现的方法不同,但是原理、步骤还是共同的。关于模拟PLL。可以参考一片文章: http://www.sohu.com/a/190569594_464086 首先在学习数字锁相环之前,我们应该先了解什么是锁相环?锁相...

DBLLLLLLLL的博客 5万+

企业多部门网络隔离实战:用华为交换机VLAN+Trunk实现行政/技术部安全隔离

本文详细介绍了如何利用华为交换机的VLAN划分与Trunk链路技术,实现企业行政与技术部门间的网络逻辑隔离。通过具体的配置案例,阐述了Access与Trunk端口的工作原理、单交换机与多交换机环境下的部署策略,并延伸至三层网关部署与ACL访问控制,为企业构建安全、高效的核心网络提供实战指导。

p4q5r6s7t的博客 577

929. Unique Email Addresses*

929. Unique Email Addresses* https://leetcode.com/problems/unique-email-addresses/ 题目描述 Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode....

珍妮的选择的博客 728

STM32 BootLoader 入门教程:从原理到 APP 跳转实现

在 STM32 项目开发中,BootLoader 通常用于实现固件升级、程序引导和应用程序校验。本文从最基础的 BootLoader 原理开始,讲解 STM32 内部 Flash 分区设计、APP 地址偏移、向量表重定位、BootLoader 跳转 APP 的核心代码,以及实际开发中常见的问题。本文适合刚开始接触 STM32 BootLoader、IAP 在线升级、串口升级、OTA 升级的开发者阅读。

lidecong133的博客 1665

929. Unique Email Addresses

题目来源: https://leetcode.com/problems/unique-email-addresses/ 自我感觉难度/真实难度:easy/easy 题意: 分析: 熟悉使用string的相关操作即可 自己的代码: class Solution(object): def numUniqueEmails(self, emails): ...

weixin_30753873的博客 107

使用GitLab+Drone CI持续集成自动部署web项目,图文详细

kind: pipeline # 定义对象类型,还有secret和signature两种类型 type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型 name: mall-tiny-drone # 定义流水线名称 steps: # 定义流水线执行步骤,这些步骤将顺序执行 - name: package # 流水线名称 image: maven:3-jdk-8 # 定义创建容器的Docker镜像 volumes: # 将容器内目录挂载到宿主机,仓库

4105

双三相电机控制避坑指南:为什么你的SVPWM谐波大?四矢量调制实战解析

本文深入解析双三相电机控制中SVPWM谐波大的问题,并提供四矢量调制实战方案。通过分析谐波来源、四矢量调制原理及工程实现步骤,显著降低电流THD至3-5%,提升系统效率2.3个百分点。特别适合需要优化电机控制的工程师参考。

weixin_30645617的博客 397

929 Unique Email Addresses

929 Unique Email Addresses 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 le...

wilzxu的博客 440

从零构建企业级多智能体系统:LangGraph 全流程实战 + 部署指南(含代码与架构图)

> 在大模型应用爆发的今天,如何构建一个可协作、可调试、可部署的多智能体系统?LangGraph 正在成为工程师的新宠。本文从原理剖析、流程建模、代码实战到前后端部署,手把手带你用 LangGraph 构建一个企业级 AI 助理系统,整合财务分析、法务审阅、报告生成与图表可视化等 Agent 模块,全面打通从用户输入到报告输出的全链路闭环。适合有工程思维的 AI 架构师、Agent 研发人员、以及大模型项目实践者。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 3449

leetcode (Unique Email Addresses)

Title:Unique Email Addresses   929 Difficulty:Easy 原题leetcode地址: https://leetcode.com/problems/unique-email-addresses/   1.   Set集合的唯一性 时间复杂度:O(n),一次一层for循环。 空间复杂度:O(n),申请Set集合。 /** *...

hsx1612727380的专栏 244

Python逻辑回归——以车险定价为例(附代码)

保费定价也成为费率厘定,是保险公司运营的环节之一。其过程是根据保单(被保险人)的损失经验和其他相关信息建立模型,并且对未来的保险成本(赔款、代理人佣金、一般管理费用、理赔费用以及支持该业务所需的资本金成本)进行预测的过程。保险公司实际使用的费率还会受到市场供求关系和公司自身发展战略的影响。汽车保险也称机动车辆保险,失意机动车辆本身及其第三者责任等为保险标的的一种运输工具险,在非寿险井算领域中占有重要地位。

m0_62929945的博客 1984

解决宿主机Ping不通虚拟机的问题

在使用虚拟机的过程中,我们常常会遇到宿主机和虚拟机之间无法相互通信的问题。具体来说,我们要查看虚拟机和宿主机的 IP 地址,然后尝试进行 Ping 测试。在某些情况下,我们可能发现 Ping 虚拟机不通,接下来我将分享如何解决这个问题。

howard2005的专栏 7万+

leetcode929 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 lowerc...

datai3890的博客 276

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

LeetCode 929. Unique Email Addresses

Every email consists of a local name and a domain name, separated by the @ sign. For example, inalice@leetcode.com,aliceis the local name, andleetcode.comis the domain name. Besides lowercase l...

lmxr133的博客 302

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

929. Unique Email Addresses(java)

经过一轮来不及准备的面试,我应该知道了自己几斤几两了,,, 奋发刷题,记录下自己的解题过程,以及一些遇到的需要注意的问题。 意向java方向,java还是在大一学的,大三重拾处处是坑。 上题:大意是要去掉email里面本地名里面的 “.” 和“+”后面的部分。 public static int numUniqueEmails(String[] emails) { i...

github_38237196的博客 322

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

上一篇: Max Increase to Keep City Skyline
下一篇: To Lower Case
linux_player_c
博客等级 码龄13年 214粉丝 134原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值