- Leetcode 929: Unique email addresses
- Level: Easy
- Link
My Approach
- For each email addresses, split the local and domain address
- If '.' in the local address, remove it.
- If '+' in the local address, remove strings after the index
- Combine the local and domain address and add them to a set
- Return the length of the set
class Solution:
def numUniqueEmails(self, emails: List[str]) -> int:
res = set()
for i in range(len(emails)):
splitidx = emails[i].index('@')
local = emails[i][0:splitidx]
domain = emails[i][splitidx:]
local = local.replace('.', '')
if '+' in local:
local = local[0: local.index('+')]
address = local + domain
res.add(address)
return (len(res))
'개발공부 > algorithm' 카테고리의 다른 글
[Leetcode][python] 120: triangle - DP (0) | 2021.04.29 |
---|---|
[Leetcode][python] 973: K closest point to the origin (0) | 2021.04.28 |
[Leetcode][python] 1161: Maximum Level of sum of a binary tree - BFS (0) | 2021.04.27 |
[Leetcode][python] 257: binary tree paths - DFS (0) | 2021.04.27 |
[Leetcode][python] 733: flood fill - bfs (0) | 2021.04.25 |