Easy Solution using case Statement


  • 0
    C

    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;


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.