Easy in 0(n) cpp solution


#1
vector<int> Solution::solve(TreeNode* A) {
queue<TreeNode*>q;
vector<int> v;

q.push(A);
while(!q.empty())
{
    TreeNode* t = q.front();  
    q.pop();
    v.push_back(t->val);
    if(t->right)
    {q.push(t->right);}
    if(t->left)
    {q.push(t->left);}
}

std::reverse(v.begin(),v.end());
return v;

}