Changing the function parameters to by reference made my code to pass TLE can anyone explain

programming
Tags: #<Tag:0x00007f24263148f8>

#1
vector<int> Solution::postorderTraversal(TreeNode* A) 

{
vectorres;
if(A==NULL)
return res;
else if(A->left==NULL&&A->right==NULL)
{
res.push_back(A->val);
return res;
}
stack<TreeNode*> s2;
res.push_back(A->val);
s2.push(A);
while(!s2.empty())
{
while(!s2.empty()&&s2.top()->right)
{
TreeNode *t=s2.top();
s2.push(t->right);
res.push_back(t->right->val);
}
while(!s2.empty()&&!s2.top()->left)
s2.pop();
if(!s2.empty())
{
TreeNode *prev=s2.top();
s2.pop();
if(prev->left)
{
s2.push(prev->left);
res.push_back(prev->left->val);
}
}else
break;
}
reverse(res.begin(),res.begin()+res.size());
return res;
}