Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e82ec07

Browse files
Create 3228. Maximum Number of Operations to Move Ones to the End.cpp
1 parent 2734cd6 commit e82ec07

File tree

1 file changed

+23
-0
lines changed

1 file changed

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /