inblog logo
|
silver
    SQL문제풀기

    [SQL문제풀기] Binary Tree Nodes

    silver's avatar
    silver
    Apr 15, 2025
    [SQL문제풀기] Binary Tree Nodes
    Contents
    문제MySQL, Oracle, MS SQL Server, DB2

    문제

    Binary Tree Nodes | HackerRank
    Write a query to find the node type of BST ordered by the value of the node.
    Binary Tree Nodes | HackerRank
    https://www.hackerrank.com/challenges/binary-search-tree-1/problem?isFullScreen=true
    Binary Tree Nodes | HackerRank

    MySQL, Oracle, MS SQL Server, DB2

    내가 작성한 정답

    select n, case when p is null then 'Root' when n in (select p.n from bst p left join bst d on p.n = d.p where d.n is null) then 'Leaf' else 'Inner' end tree from bst order by n;

    내가 작성한 정답 2

    select n, case when p is null then 'Root' when n not in (select p from bst where p is not null) then 'Leaf' else 'Inner' end tree from bst order by n;
    Share article

    silver

    RSS·Powered by Inblog