leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1769.cpp (457B)
0 class Solution { 1 public: 2 vector<int> minOperations(const string &boxes) { 3 vector<int> res(boxes.size(), 0); 4 5 for (int i = 0, ops = 0, cnt = 0; i < boxes.size(); i++) { 6 res[i] += ops; 7 ops += cnt += (boxes[i] == '1'); 8 } 9 10 for (int i = boxes.size() - 1, ops = 0, cnt = 0; i >= 0; i--) { 11 res[i] += ops; 12 ops += cnt += (boxes[i] == '1'); 13 } 14 15 return res; 16 } 17 };