Duplicate Emails — LeetCode 182 Python Solution
EasyDatabase
- Problem
- #182
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Report every email address that is recorded more than once. The Person table has id (int, primary key) and email (varchar), one row per record, and the addresses never contain uppercase letters. Each duplicated address should be listed once, in a column named Email.
Example
- Input
- Person(id, email) = (1, 'ana@example.com'), (2, 'cleo@example.com'), (3, 'ana@example.com'), (4, 'ben@example.com'), (5, 'ben@example.com')
- Output
- Email = 'ana@example.com', 'ben@example.com'
- Explanation
- Both addresses occur twice, so each is reported once; cleo@example.com occurs once and is excluded.
Python solution
Python
import pandas as pd
def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
results = pd.DataFrame()
results = person.loc[person.duplicated(subset=["email"]), ["email"]]
return results.drop_duplicates()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 182. Duplicate Emails?
- LeetCode 182. Duplicate Emails is rated Easy on LeetCode.
- What topics does LeetCode 182. Duplicate Emails cover?
- LeetCode 182. Duplicate Emails is tagged Database on LeetCode.