AC Solution

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

  • 1

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

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

  • 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.