标签:res add object email 处理 串处理 set enumerate ret
简答题,字符串处理
class Solution(object): def numUniqueEmails(self, emails): """ :type emails: List[str] :rtype: int """ ans = [] for i, em in enumerate(emails): add, at = -1, -1 size = len(em) for j in range(size): if em[j] == ‘@‘: at = j break if em[j] == ‘+‘: if add == -1: add = j if add != -1: ans.append(em[:add].replace(‘.‘,‘‘) + em[at:]) else: ans.append(em[:at].replace(‘.‘,‘‘)+em[at:]) ans = set(ans) return len(ans)
Leetcode 929. Unique Email Addresses
标签:res add object email 处理 串处理 set enumerate ret
原文地址:https://www.cnblogs.com/zywscq/p/10532945.html