AC Solution


  • 2
    R
    select T.id, 
    IF(isnull(T.p_id), 'Root', IF(T.id in (select p_id from tree), 'Inner', 'Leaf')) Type 
    from tree T
    

  • 0
    M

    Mine is similar.. but not quite as succinct...

    select t1.id as 'Id', (if (t1.p_id is NULL, 'Root', if ((select distinct p_id from tree where t1.id = p_id) is not NULL, 'Inner', 'Leaf'))) as 'Type' from tree as t1 order by t1.id;


  • 0

    @richarddia Your solution is very helpful. Thanks!


Log in to reply
 

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