-
Binary Tree Nodes MySQLHackerRank/SQL 2023. 2. 11. 21:16
문제
https://www.hackerrank.com/challenges/binary-search-tree-1/problem
Binary Tree Nodes | HackerRank
Write a query to find the node type of BST ordered by the value of the node.
www.hackerrank.com
풀이
- CASE문과 서브쿼리를 이용한다.
SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN N NOT IN (SELECT DISTINCT P FROM BST WHERE P IS NOT NULL) THEN 'Leaf' ELSE 'Inner' END FROM BST ORDER BY N
참조
https://jogrammer.tistory.com/249
[해커랭크(HackerRank)] Binary Tree Nodes (MySQL)
문제 2진 트리 문제. N은 이진 트리의 노드 값, P는 N의 상위 항목 Root → 최상위 노드인 경우, 부모가 없는 노드 → 5가 최상위 노드 Leaf → 최하위 노드인 경우, 자식이 없음 → 1, 3, 6, 9 → n이 p의
jogrammer.tistory.com
'HackerRank > SQL' 카테고리의 다른 글
Weather Observation Station 20 MySQL (0) 2023.02.15 Top Earners MySQL (0) 2023.02.13 Occupations MySQL (0) 2023.02.10 The PADS MySQL (0) 2023.02.10 The Report MySQL (0) 2023.02.09