You are viewing a single comment's thread. Return to all comments →
C# Solution using Linked List
class Solution { static void Main(String[] args) { var linkedList = new LinkedList<string>(); var queries = int.Parse(Console.ReadLine()); for (var i = 0; i < queries; i++) { var ops = Console.ReadLine().Split(); switch(ops[0]) { case "1": Append(linkedList, ops[1]); break; case "2": DeleteCharacters(linkedList, int.Parse(ops[1])); break; case "3": Print(linkedList, int.Parse(ops[1])-1); break; case "4": UndoOperation(linkedList); break; } } static void Append(LinkedList<string> l, string data) { var s = data; if (l.Last != null) { s = $"{l.Last.Value}{data}"; } l.AddLast(s); } static void DeleteCharacters(LinkedList<string> l, int k) { if (l.Last == null) { return; } var s = l.Last.Value; var index = s.Length - k; s = s.Remove(index); l.AddLast(s); } static void Print(LinkedList<string> l, int index) { if (l.Last == null) { return; } var s = l.Last.Value[index]; Console.WriteLine(s); } static void UndoOperation(LinkedList<string> l) { if (l.Last == null) { return; } l.RemoveLast(); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Text Editor
You are viewing a single comment's thread. Return to all comments →
C# Solution using Linked List