https://leetcode.com/problems/tree-node/
select id,
case when p_id is null then 'Root'
when id in (select distinct p_id from Tree) then 'Inner'
else 'Leaf' end as type
from Tree;
best
select
id, IF(ISNULL(p_id), 'Root',
IF(id in (SELECT p_id from tree),'Inner', 'Leaf')) as Type
from Tree
728x90
반응형
'자료구조 알고리즘 > 코딩테스트' 카테고리의 다른 글
70. Climbing Stairs (0) | 2022.05.31 |
---|---|
176. Second Highest Salary (0) | 2022.05.30 |
1795. Rearrange Products Table (0) | 2022.05.30 |
1965. Employees With Missing Information (0) | 2022.05.30 |
1527. Patients With a Condition (0) | 2022.05.30 |