Skip to content

Commit

Permalink
Time: 1 ms (97.36%), Space: 41.6 MB (36.08%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Jan 1, 2025
1 parent 5716082 commit 081c062
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public int maxScore(String s) {
int ones = 0;
int current = s.charAt(0) == '0' ? 1 : 0;
int score = current;
for (int i = 1; i < s.length() - 1; i++) {
if (s.charAt(i) == '0') current++;
else {
ones++;
current--;
}
score = Math.max(score, current);
}
return ones + score + (s.charAt(s.length() - 1) == '1' ? 1 : 0);
}
}

0 comments on commit 081c062

Please sign in to comment.