You are viewing a single comment's thread. Return to all comments →
Here is my C++ solution:
int equalStacks(vector<int> h1, vector<int> h2, vector<int> h3) { auto ref = [&](){ std::vector<vector<int>*> v_; v_.push_back(&h1); v_.push_back(&h2); v_.push_back(&h3); return v_; }(); int hight[3]{}; for (auto it : h1) hight[0] += it; for (auto it : h2) hight[1] += it; for (auto it : h3) hight[2] += it; while (true) { if (hight[0] == hight[1] && hight[0] == hight[2]) return hight[0]; int indx = 0; if (hight[1] > hight[indx]) indx = 1; else if (hight[2] > hight[indx]) indx = 2; auto el = ref[indx]->front(); ref[indx]->erase(ref[indx]->begin()); hight[indx] -= el; } return hight[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 →
Here is my C++ solution: