Small help ;) Linear O(n)


#1

vector Solution::solve(TreeNode* A) {
queue <TreeNode *> Q;
Q.push(A);
vector ans;
while (!Q.empty())
{
A = Q.front();
Q.pop();
ans.push_back(A->val);
if (A->right)
Q.push(A->right);
if (A->left)
Q.push(A->left);
}
reverse(ans.begin(),ans.end());
return ans;
}.