You are viewing a single comment's thread. Return to all comments →
public static int equalStacks(List<Integer> h1, List<Integer> h2, List<Integer> h3) { int sum1 = h1.stream().reduce(0, (a,b) -> a + b); int sum2 = h2.stream().reduce(0, Integer::sum); int sum3 = h3.stream().mapToInt(Integer::intValue).sum(); while(true) { if(sum1 == sum2 && sum1 == sum3) return sum1; if(sum1 >= sum2 && sum1 >= sum3) sum1 -= h1.remove(0); else if(sum2 >= sum1 && sum2 >= sum3) sum2 -= h2.remove(0); else if(sum3 >= sum1 && sum3 >= sum2) sum3 -= h3.remove(0); } }
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 →