mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
251116
This commit is contained in:
17
25/11/3228-unfinish.cpp
Normal file
17
25/11/3228-unfinish.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user