classSolution:deffindLeaves(self,root: Optional[TreeNode]) -> List[List[int]]: ans = []defdfs(root):ifnot root:return-1 left =dfs(root.left) right =dfs(root.right) h =max(left, right)+1iflen(ans)== h: ans.append([]) ans[h].append(root.val)return hdfs(root)return ans