Skip to content

Commit dca6518

Browse files
Create 1422-maximum-score-after-splitting-a-string.java
1 parent 5e4ae49 commit dca6518

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int maxScore(String s) {
3+
int zero = 0, one = 0;
4+
int res = 0;
5+
6+
for(char c: s.toCharArray()){
7+
if(c == '1')
8+
one += 1;
9+
}
10+
for(int i = 0; i < s.length()-1; i++){
11+
char c = s.charAt(i);
12+
if(c == '0')
13+
zero += 1;
14+
else
15+
one -= 1;
16+
res = Math.max(res, zero + one);
17+
}
18+
return res;
19+
}
20+
}

0 commit comments

Comments
 (0)