You are viewing a single comment's thread. Return to all comments →
c# solution
public static int equalStacks(List<int> h1, List<int> h2, List<int> h3) { Queue<int> stack = new Queue<int>(h1); Queue<int> stack2 = new Queue<int>(h2); Queue<int> stack3 = new Queue<int>(h3); int tam1 = stack.Sum(); int tam2 = stack2.Sum(); int tam3 = stack3.Sum(); while(!(tam1 == tam2 && tam2 == tam3 && tam3 == tam1)) { if(tam1 > tam2) { if (stack.Count == 0) { tam1 = 0; } else { tam1 = tam1 - stack.First(); stack.Dequeue(); } } if(tam2 > tam3) { if (stack2.Count == 0) { tam2 = 0; } else { tam2 = tam2 - stack2.First(); stack2.Dequeue(); } } if(tam3 > tam1) { if (stack3.Count == 0) { tam3 = 0; } else { tam3 = tam3 - stack3.First(); stack3.Dequeue(); } } } return tam1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
c# solution