We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticintequalStacks(List<int>h1,List<int>h2,List<int>h3){Stack<int>stack1=newStack<int>(h1);Stack<int>stack2=newStack<int>(h2);Stack<int>stack3=newStack<int>(h3);// Counterintc1=0;intc2=0;intc3=0;// Sum of each stackintsum1=stack1.Sum();intsum2=stack2.Sum();intsum3=stack3.Sum();while(sum1!=sum2||sum2!=sum3||sum3!=sum1){if(sum1>=sum2&&sum1>=sum3){sum1-=h1[c1];c1++;}elseif(sum2>=sum1&&sum2>=sum3){sum2-=h2[c2];c2++;}elseif(sum3>=sum1&&sum3>=sum2){sum3-=h3[c3];c3++;}}returnsum1;}
Cookie support is required to access HackerRank
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# Simple Solution