pandas || 4 lines, to_list || T/S: 99% / 99%
\nimport pandas as pd\n\ndef tree_node(tree: pd.DataFrame) -> pd.DataFrame:\n\n    tree = tree.where(pd.notnull(tree), -1)\n    ids, p_ids, nodes = tree[\'id\']
```\nimport pandas as pd\n\ndef tree_node(tree: pd.DataFrame) -> pd.DataFrame:\n\n    tree = tree.where(pd.notnull(tree), -1)\n    ids, p_ids, nodes = tree[\'id\'].to_list(),tree[\'p_id\'].to_list(), []\n\n    for i in range(len(ids)):\n\n        if p_ids[i] == -1   : nodes.append("Root" )\n        elif ids[i] in p_ids: nodes.append("Inner")\n        else                : nodes.append("Leaf" )\n\n    return pd.DataFrame({\'id\':ids,\'type\':nodes})\n```\n[https://leetcode.com/problems/tree-node/submissions/1072187547/](https://leetcode.com/problems/tree-node/submissions/1072187547/)\n\nI could be wrong, but I think that time complexity is *O*(*N*)  and space complexity is *O*(*U*), in which *N* ~ `len()`.
['Pandas']