class MyQueue
{
private:
stack<int> in_stack, out_stack;
void in2out()
{
while (!in_stack.empty())
{
out_stack.push(in_stack.top());
in_stack.pop();
}
}
public:
MyQueue()
{
}
void push(int x)
{
in_stack.push(x);
}
int pop()
{
if (out_stack.empty())
{
in2out();
}
auto temp{ out_stack.top() };
out_stack.pop();
return temp;
}
int peek()
{
if (out_stack.empty())
{
in2out();
}
return out_stack.top();
}
bool empty()
{
return in_stack.empty() && out_stack.empty();
}
};
class MyStack
{
private:
queue<int> stack;
public:
MyStack()
{
}
void push(int x)
{
stack.push(x);
if (stack.size() > 1)
{
for (int i = 0; i < stack.size() - 1; i++)
{
auto temp{ stack.front() };
stack.pop();
stack.push(temp);
}
}
}
int pop()
{
auto temp{ stack.front() };
stack.pop();
return temp;
}
int top()
{
return stack.front();
}
bool empty()
{
return stack.empty();
}
};
class Solution
{
public:
bool isValid(string s)
{
stack<char> stk;
for (auto& ch : s)
{
if (ch == '(' || ch == '{' || ch == '[')
{
stk.push(ch);
}
else if (stk.empty())
{
return false;
}
else
{
if (stk.top() == '(' && ch == ')' ||
stk.top() == '{' && ch == '}' ||
stk.top() == '[' && ch == ']')
{
stk.pop();
}
else
{
return false;
}
}
}
return stk.empty();
}
};
class Solution
{
public:
string removeDuplicates(string s)
{
string ans;
for (auto& ch : s)
{
if (ans.empty())
{
ans.push_back(ch);
}
else
{
if (ans.back() == ch)
{
ans.pop_back();
}
else
{
ans.push_back(ch);
}
}
}
return ans;
}
};