There was an error while loading. Please reload this page.
1 parent 5e0cce9 commit 436c292Copy full SHA for 436c292
3707-equal-score-substrings/3707-equal-score-substrings.ts
@@ -3,11 +3,10 @@ const scoreBalance = (s: string): boolean => {
3
4
// Build prefix sum array: prefixSum[i] = sum of scores from index 0 to i
5
const prefixSum: number[] = new Array(stringLength);
6
- prefixSum[0] = s.charCodeAt(0) - 96;
7
8
- for (let index = 1; index < stringLength; index++) {
+ for (let index = 0; index < stringLength; index++) {
9
const charScore = s.charCodeAt(index) - 96;
10
- prefixSum[index] = prefixSum[index - 1] + charScore;
+ prefixSum[index] = (index > 0 ? prefixSum[index - 1] : 0) + charScore;
11
}
12
13
const totalScore = prefixSum[stringLength - 1];
0 commit comments