forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_1422.java
More file actions
25 lines (24 loc) · 728 Bytes
/
_1422.java
File metadata and controls
25 lines (24 loc) · 728 Bytes
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
package com.fishercoder.solutions;
public class _1422 {
public static class Solution1 {
public int maxScore(String s) {
int zeroes = s.charAt(0) == '0' ? 1 : 0;
int ones = 0;
for (int i = 1; i < s.length(); i++) {
if (s.charAt(i) == '1') {
ones++;
}
}
int maxScore = zeroes + ones;
for (int i = 1; i < s.length() - 1; i++) {
if (s.charAt(i) == '0') {
zeroes++;
} else {
ones--;
}
maxScore = Math.max(maxScore, zeroes + ones);
}
return maxScore;
}
}
}