Notice
Recent Posts
Recent Comments
Link
복's
[ LeetCode - 182 ] Duplicate Emails 본문
728x90
https://leetcode.com/problems/duplicate-emails/description/
Duplicate Emails - LeetCode
Can you solve this real interview question? Duplicate Emails - Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | email | varchar | +-------------+---------+ id is the primary key (column with unique val
leetcode.com
중복되는 email 컬럼이 있는 경우만 출력하면 되는 문제로 2가지의 풀이로 풀어봤다.
문제가 너무 빨리 풀려서 다른 풀이로도 풀었다.
[ 📌 풀이 ]
1) group by를 이용해서 email 별로 묶고 count를 통해서 개수를 확인해서 1개 이상인 경우 출력 하기
2) 조인을 통해서 테이블을 붙인 다음에 email은 같으나 id가 다른 row를 출력하기
[ 📌 코드 풀이1 - Oracle ]
-- Author : Lee In Bok
-- Date : 2023.12.01(Fri)
-- Spend Time: 01m 32s
-- Runtime : 855 ms (Beats 61.66%)
-- Algoritm : Distinct, Aggregattion
select email as Email
from Person
group by email
having count(email) > 1
[ 📌 코드 풀이2 - Oracle ]
select distinct p1.email AS Email
from Person p1
inner join Person p2
on p1.email = p2.email
and p1.id <> p2.id
[ 📌 결과 - Oracle ]
728x90
'알고리즘 > LeetCode' 카테고리의 다른 글
[ LeetCode - 104 ] Maximum Depth of Binary Tree (1) | 2023.12.01 |
---|---|
[ LeetCode - 1189 ] Maximum Number of Balloons (1) | 2023.11.26 |
[ LeetCode - 180 ] Consecutive Numbers (0) | 2023.11.25 |
[ LeetCode - 178 ] Rank Scores (2) | 2023.11.20 |
[ LeetCode - 176 ] Second Highest Salary (1) | 2023.11.18 |