3228.cpp (429B)
1 class Solution { 2 public: 3 int maxOperations(const string &s) const { 4 const int n = size(s); 5 int res = 0, count = 0; 6 7 for (int i = 0; i < n;) { 8 const int start = i; 9 10 while (i < n && s[i] == s[start]) 11 i++; 12 13 if (s[start] == '0') 14 res += count; 15 else 16 count += i - start; 17 } 18 return res; 19 } 20 };