[leetcode] 929. Unique Email Addresses @ python

LeetCode --- 929. Unique Email Addresses 解题报告 Everyvalid emailconsists of alocal nameand adomain name, separated by the'@'sign. Besides lowercase letters, the email may contain one or more'.'or'+'. For example, in"alice@leetcode.com","alice"is thelocal name, and"leetcode.com"is thedo... 阅读详情

原题

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.

解法

字符串处理. 构造一个字典d存放每个domain对应的local name, 遍历emails, 将domain和local name分离出来, local name进行处理, 将不重复的local name加入字典. 最后遍历字典的键, 将值的长度相加.
Time: O(n)
Space: O(n)

代码

class Solution(object):
    def numUniqueEmails(self, emails):
        """
        :type emails: List[str]
        :rtype: int
        """
        d = collections.defaultdict(list)
        for email in emails:            
            i = email.index('@')
            local = email[:i]
            domain = email[i+1:]
            # process local name
            local = local.replace('.', '')
            if '+' in local:
                index = local.index('+')
                local = local[:index]
            # process address
            if local not in d[domain]:
                d[domain].append(local)
        ans = 0
        for key in d:
            ans += len(d[key])
        return ans
IBM DS存储Storage Manager客户端深度排错指南 IBM DS系列存储的Storage Manager客户端并非普通图形管理工具,而是基于SNMP与私有SOAP协议的底层设备通信代理,其运行高度依赖固件版本匹配、TCP/IP栈精准配置及SSL证书信任链。理解其作为嵌入式管理代理的原理,有助于规避因网络层不兼容、服务注册失败或证书未导入导致的连接中断。该技术方案广泛应用于金融、制造等行业的DS3500/DS5020等中端存储运维场景,支撑LUN映射、RAID重建与日志采集等关键任务。本文聚焦Windows环境下的服务化部署、端口监听验证与跨层连通性诊断,覆盖 阅读详情

相关推荐

博图编写温度程序_s7 smart200的CRC-16校验程序

最近做一个小项目,项目中采用485自由口通讯方式,使用一台西门子S7 smart200对一台冷水机做多个状态和温度做监控,并能对冷水机进行启停控制,和参数设置,因为冷水机的协议不是标准modbus格式,所以要自己编写通信协议。其中要用到CRC校验,在网上找了些别人写的程序,基本上用不了。只能自力更生了。首先,找到CRC校验的算法,并理解。 下面就是我找的算法(这个网上很多),1....

weixin_39539761的博客 3062

929. Unique Email Addresses

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

BigFatSheep的博客 713

在 Windows 10 中通过 WSL2 安装 vLLM 部署本地大模型的方法和步骤

通过 WSL2 在 Windows 10 中部署 vLLM 的核心优势是兼顾 Windows 生态与 Linux 环境的 GPU 加速能力,适合需要在 Windows 下开发但依赖 vLLM 高性能推理的场景。相比原生 Windows 部署(Ollama 等工具),该方案性能更优(接近原生 Ubuntu),且支持更大模型和量化优化。若追求极致性能,建议直接使用 Ubuntu 系统;若必须依赖 Windows 工具链,WSL2 + vLLM 是当前最优选择。

当 AI 开始写文章、绘星空,甚至预测未来,您还在旁观吗?这里将剖开人工智能的思考逻辑,拆解 AI 创作的底层密码,也聊聊人工智能里的人文温度。每篇都有让你拍案的细节,快来解锁 AI 时代的神奇世界! 3754

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

uniapp+ucharts折线图toolTip不显示?别慌,手把手教你用showToolTip方法精准修复

本文详细解析了uniapp+ucharts折线图中toolTip不显示的常见问题,提供了showToolTip方法的精准修复方案。从底层原理到实战代码,帮助开发者解决触摸事件冲突、坐标计算偏差等问题,确保折线图交互提示功能稳定运行。

weixin_30316097的博客 403

E2000 RGMII0通讯异常问题总结

飞腾E2000 RGMII接YT8521,RGMII0路不通问题。

乌拉大喵喵 1630

929. Unique Email Addresses(python+cpp)

题目: 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 lowercas...

小湉湉的博客 1376

FPGA实现Gardner环定时同步:Verilog代码与Testbench实战解析

本文深入解析了在FPGA上实现Gardner环定时同步的完整过程,详细阐述了其非数据辅助的定时误差检测原理。通过Verilog代码实战,展示了内插滤波器、定时误差检测器、环路滤波器和数控振荡器等核心模块的设计,并提供了完整的Testbench验证方法,帮助开发者解决数字通信系统中的时钟同步难题。

gpt4scribbler的博客 576

[LeetCode] 929. Unique Email Addresses My SubmissionsBack to Contest

题:https://leetcode.com/contest/weekly-contest-108/problems/unique-email-addresses/ 题目 Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.co...

u013383813的博客 689

嵌入式工程师必学(118):MCU的硬件定时器和中断

大多数微处理器都有一个或多个可编程硬件定时器,这些定时器包括对中断的支持。可以有不同类型的计时器,用于不同的应用程序。例如,LPC1768 具有四个 32 位通用定时器、一个看门狗定时器、一个重复中断定时器、一个系统滴答定时器、一个正交编码器接口、6 个 PWM 输出和一个支持中断的实时时钟。硬件定时器用于计时和计数作,允许处理器在 timer 进程运行时继续执行其他进程。硬件定时器是一种使用 clock 信号来增加 register 的电路。

码农17年的博客 211

Autosar诊断实战系列07-Dcm之0x19 06扩展数据配置及工程问题讨论

19 06扩展数据如何配置?如果某DTC没有出现过故障扩展数据该如何响应?

initiallizer的博客 1704

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

作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录题目描述题目大意解题方法参考资料日期 题目地址:https://leetcode.com/problems/unique-email-addresses/description/ 题目描述 Every email consists of a local name and a dom...

负雪明烛 3045

QGIS之二十六pbf转osm转shp

QGIS之二十六pbf转osm转shp

yilvyangguang520的博客 7499

929:Unique Email Addresses解题笔记

标题 929:Unique Email Addresses解题笔记 1.题目描述 每封电子邮件包含一个本地名称和一个域名,用@符号分隔。 例如,在alice@leetcode.com中,alice是本地名称,leetcode.com是域名。 除了小写字母,这些邮件可能还包含 ‘.’ 或 ‘+’。 如果您在电子邮件地址的本地名称部分的某些字符之间添加句点(’.’),那么发送到该地址的邮件将被转发...

xulu95的博客 639

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

LeetCode 929 Unique Email Addresses--python一行解法,Java解法

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

个人博客 712

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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

weixin_30677617的博客 602

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

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

Leetcode 929.独特的电子邮件地址(Unique Email Addresses)

Leetcode 929.独特的电子邮件地址 1 题目描述(Leetcode题目链接)   每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔。 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名。 除了小写字母,这些电子邮件还可能包含 ‘.’ 或 ‘+’。 如果在电子邮件地址的本地名称部分中的某些字符之间添加句点(’.’),则发往那里的邮件将会转发到本地名称中没有点的同一地址。例如,"alice.z@leetcode.com” 和 “

qq_39378221的博客 1027

LeetCode - 929. Unique Email Addresses

929. Unique Email Addresses class Solution(object): def numUniqueEmails(self, emails): """ :type emails: List[str] :rtype: int """ res = set() for...

real_lisa的博客 177

Leetcode-929. Unique Email Addresses

—Easy https://leetcode.com/problems/unique-email-addresses/ Code:   class Solution: def numUniqueEmails(self, emails) -&gt; int: new_em = [] for elt in emails: i...

Muqianli的博客 390

leetcode 929. Unique Email Addresses

class Solution(object): def numUniqueEmails(self, email): """ :type emails: List[str] :rtype: int """ result = [] for i in range(len(email)): ...

cainiaohudi的博客 636

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. If you add pe...

weixin_30247781的博客 274

LeetCode 929. Unique Email Addresses

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

weixin_30632899的博客 105

Leetcode easy - python 3

771. Jewels and Stones count 函数:返回字符串中某个字符的个数 class Solution: def numJewelsInStones(self, J: str, S: str) -> int: n = 0 for j in J: n += S.count(j) return n ...

jiachengdaidai的博客 295

LeetCode-Unique Email Addresses

LeetCode Java Unique Email Addresses

坟头草一米七五 1403
上一篇: [leetcode] 91. Decode Ways @ python
下一篇: [leetcode] 339. Nested List Weight Sum @ python
闲庭信步的空间
博客等级 码龄9年 86粉丝 416原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值