Instead of really doing finding/removing again and again, we can do it in one pass and get all results.

One thing I want to clarify is, even if you do it in the naive way (find all leaves and then remove them and then find all leaves again and removes them), the complexity is also O(n), just with a bigger constant.

```
class Solution {
vector<vector<int>> result;
int solve(TreeNode * root)
{
if(root == nullptr)
return -1;
if (root->left == nullptr && root->right == nullptr)
{
if (result.empty())
result.emplace_back();
result[0].push_back(root->val);
return 0;
}
int l = solve(root->left);
int r = solve(root->right);
int level = max(l, r) + 1;
if (level >= result.size())
result.emplace_back();
result[level].push_back(root->val);
return level;
}
public:
vector<vector<int>> findLeaves(TreeNode* root) {
solve(root);
return result;
}
};
```