24. Insert an Element at the Bottom of a Stack
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution{
public:
stack<int> insertAtBottom(stack<int> st,int x)
{
stack<int>temp;
while (!st.empty())
{
temp.push(st.top());
st.pop();
}
st.push(x);
while (!temp.empty())
{
st.push(temp.top());
temp.pop();
}
return st;
}
};Contribution and Support
Last updated