leetcode

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

1422.cpp (356B)


      1 class Solution {
      2   public:
      3     int maxScore(const string &s) const {
      4         int res = 0, zero = 0, one = count(begin(s), end(s), '1');
      5         for (int i = 0; i < size(s) - 1; i++) {
      6             if (s[i] == '1')
      7                 one--;
      8             else
      9                 zero++;
     10             res = max(res, zero + one);
     11         }
     12         return res;
     13     }
     14 };