Skip to content

Commit

Permalink
Create 1422. Maximum Score After Splitting a String (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Jan 1, 2025
2 parents d2243b0 + efdb9b3 commit 20a6bd3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 1422. Maximum Score After Splitting a String
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
int maxScore(string s) {
int m=0,o=0,z=0,n=s.length();
for(int i=0;i<=n;i++){
if(s[i]=='1') o++;
}
for(int i=0;i<n-1;i++){
if(s[i]=='0') z++;
else o--;
m=max(m,z+o);
}
return m;
}
};

0 comments on commit 20a6bd3

Please sign in to comment.