You are viewing a single comment's thread. Return to all comments →
C# solution:
using System.Collections.Generic; class Solution { static void Main(String[] args) { (Stack<int> s1, Stack<int> s2) = (new(), new()); var n = int.Parse(Console.ReadLine()); for (var _ = 0; _ < n; _++) { var parameters = Console.ReadLine().Split(); var operation = parameters[0]; switch (operation) { case "1": s2.Push(int.Parse(parameters[1])); break; case "2": case "3": if (s1.Count == 0) { while (s2.Count > 0) { s1.Push(s2.Pop()); } } if (operation == "3") { Console.WriteLine(s1.Peek()); break; } s1.Pop(); break; default: break; } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
C# solution: