EasyNo. 0182
Duplicate Emails — LeetCode 182 Python Solution
- Topics
- Database
- 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
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
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0181 | Employees Earning More Than Their Managers | Easy |
| 0183 | Customers Who Never Order | Easy |
| 0180 | Consecutive Numbers | Medium |
| 0184 | Department Highest Salary | Medium |
| 0185 | Department Top Three Salaries | Hard |
| 0178 | Rank Scores | Medium |
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.