일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- DeepLearning
- stak
- CBOW
- Numpy
- PPMI
- 신경망
- sort
- boj
- backward
- Sigmoid
- kakao
- 자연어처리
- Programmers
- SQL
- FullyConnectedLayer
- MySQL
- Word2vec
- 프로그래머스
- dl
- algorithm
- Stack
- 파이썬
- Python
- Heap
- select
- skip-gram
- que
- 딥러닝
- affine
- hash
Archives
- Today
- Total
혜온의 이것저것
[HackerRank] Binary Tree Nodes (MySQL) 본문
문제
You are given a table, BST, containing two columns: N and P, where N represents the value of a node in Binary Tree, and P is the parent of N.
Write a query to find the node type of Binary Tree ordered by the value of the node. Output one of the following for each node:
- Root: If node is root node.
- Leaf: If node is leaf node.
- Inner: If node is neither root nor leaf node.
Sample Input
Sample Output
1 Leaf
2 Inner
3 Leaf
5 Root
6 Leaf
8 Inner
9 Leaf
Explanation
The Binary Tree below illustrates the sample:
풀이
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) node
from BST
order by n
'Data Analysis > SQL' 카테고리의 다른 글
[HackerRank] Revising Aggregations- The Count Function (MySQL) (0) | 2022.08.12 |
---|---|
[HackerRank] New Companies (MySQL) (0) | 2022.08.11 |
[HackerRank] Occupations (MySQL) (0) | 2022.08.11 |
[HackerRank] The PADS (MySQL) (0) | 2022.08.10 |
[HackerRank] Type of Triangle (MySQL) (0) | 2022.08.10 |
Comments