Skip to content

Commit f2ae2ee

Browse files
authored
Create 1422-maximum-score-after-splitting-a-string.js
1 parent 2d682d3 commit f2ae2ee

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const maxScore = function(s) {
6+
const n = s.length
7+
let res = 0, numOfOne = 0
8+
for(let ch of s) {
9+
if(ch === '1') numOfOne++
10+
}
11+
for(let i = 0, one = 0; i < n - 1; i++) {
12+
if(s[i] === '1') one++
13+
res = Math.max(res, (i + 1 - one) + (numOfOne - one))
14+
}
15+
16+
return res
17+
};

0 commit comments

Comments
 (0)