leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2155.cpp (504B)


      1 class Solution {
      2   public:
      3     vector<int> maxScoreIndices(const vector<int> &nums) {
      4         int score = accumulate(begin(nums), end(nums), 0);
      5         vector<int> res = {0};
      6         for (int i = 0, maxi = score; i < nums.size(); i++) {
      7             score += (nums[i] == 0) ? 1 : -1;
      8 
      9             if (score < maxi) continue;
     10             if (score > maxi) {
     11                 res.clear();
     12                 maxi = score;
     13             }
     14             res.push_back(i + 1);
     15         }
     16 
     17         return res;
     18     }
     19 };