class Solution {
public int maxScore(String s) {
int total_one = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '1') {
total_one++;
}
}
int score = 0;
for (int i = 1; i < s.length(); i++) {
String left = s.substring(0, i);
int zero = 0;
int one = 0;
for (int i1 = 0; i1 < left.length(); i1++) {
if (s.charAt(i1) == '0') {
zero++;
} else {
one++;
}
}
if (zero + total_one - one > score) {
score = zero + total_one - one;
}
}
return score;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28