Skip to content

Commit e97508a

Browse files
authored
Update 1422-maximum-score-after-splitting-a-string.js
1 parent f2ae2ee commit e97508a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

1422-maximum-score-after-splitting-a-string.js

+17
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,20 @@ const maxScore = function(s) {
1515

1616
return res
1717
};
18+
19+
// another
20+
21+
/**
22+
* @param {string} s
23+
* @return {number}
24+
*/
25+
const maxScore = function(s) {
26+
const n = s.length
27+
let res = -Infinity, one = 0, zero = 0
28+
for(let i = 0; i < n; i++) {
29+
s[i] === '0' ? zero++ : one++
30+
if(i !== n - 1) res = Math.max(res, zero - one)
31+
}
32+
33+
return res + one
34+
};

0 commit comments

Comments
 (0)