Skip to content

Commit abad45a

Browse files
authored
Create 3228. Maximum Number of Operations to Move Ones to the End
1 parent eccb4c5 commit abad45a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int maxOperations(string s) {
4+
int ans = 0;
5+
int count = 0;
6+
int n = s.size();
7+
bool flag = true;
8+
9+
for (int i = 0; i < n; i++) {
10+
if (s[i] == '0' && flag) {
11+
ans += count;
12+
flag = false;
13+
}
14+
else if (s[i] == '1') {
15+
count++;
16+
flag = true;
17+
}
18+
}
19+
return ans;
20+
}
21+
};

0 commit comments

Comments
 (0)