04. Reverse a Stack
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
void Reverse(stack<int> &St) {
queue<int> temp;
while (!St.empty()) {
temp.push(St.top());
St.pop();
}
while (!temp.empty()) {
St.push(temp.front());
temp.pop();
}
}
};Contribution and Support
Last updated