leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2155.cpp (504B)
0 class Solution {
1 public:
2 vector<int> maxScoreIndices(const vector<int> &nums) {
3 int score = accumulate(begin(nums), end(nums), 0);
4 vector<int> res = {0};
5 for (int i = 0, maxi = score; i < nums.size(); i++) {
6 score += (nums[i] == 0) ? 1 : -1;
8 if (score < maxi) continue;
9 if (score > maxi) {
10 res.clear();
11 maxi = score;
12 }
13 res.push_back(i + 1);
14 }
16 return res;
17 }
18 };