Created
May 1, 2019 14:44
-
-
Save mylons/0e6284c65dc4fceaaf21cee8d8e008a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def numUniqueEmails(self, emails: List[str]) -> int: | |
uniques = set() | |
for email in emails: | |
uniques.add(parse_email(email)) | |
return len(uniques) | |
def parse_email(email: str) -> str: | |
first_half, second_half = email.split('@') | |
no_periods = first_half.replace('.', '') | |
plus_index = no_periods.find('+') | |
if plus_index > 0: | |
clean_first = no_periods[:plus_index] | |
else: | |
clean_first = no_periods | |
return f"{clean_first}@{second_half}" | |
import unittest | |
class TestSolution(unittest.TestCase): | |
def test_example_one(self): | |
emails = ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"] | |
results = 2 | |
sol_output = Solution().numUniqueEmails(emails) | |
self.assertEqual(sol_output, results) | |
def test_case_180(self): | |
emails = ["a@leetcode.com","b@leetcode.com","c@leetcode.com"] | |
results = 3 | |
sol_output = Solution().numUniqueEmails(emails) | |
self.assertEqual(sol_output, results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment