mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
17 lines
309 B
C++
17 lines
309 B
C++
#include <string>
|
|
|
|
int maxOperations(std::string s) {
|
|
int countOne = 0;
|
|
int ans = 0;
|
|
for (int i = 0; i < s.length(); i++) {
|
|
if (s[i] == '0') {
|
|
while ((i + 1) < s.length() && s[i + 1] == '0') {
|
|
i++;
|
|
}
|
|
ans += countOne;
|
|
} else {
|
|
countOne++;
|
|
}
|
|
}
|
|
return ans;
|
|
} |