Skip to content

Commit 436c292

Browse files
committed
Time: 1 ms (89.19%), Space: 57.6 MB (91.89%) - LeetHub
1 parent 5e0cce9 commit 436c292

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

3707-equal-score-substrings/3707-equal-score-substrings.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ const scoreBalance = (s: string): boolean => {
33

44
// Build prefix sum array: prefixSum[i] = sum of scores from index 0 to i
55
const prefixSum: number[] = new Array(stringLength);
6-
prefixSum[0] = s.charCodeAt(0) - 96;
76

8-
for (let index = 1; index < stringLength; index++) {
7+
for (let index = 0; index < stringLength; index++) {
98
const charScore = s.charCodeAt(index) - 96;
10-
prefixSum[index] = prefixSum[index - 1] + charScore;
9+
prefixSum[index] = (index > 0 ? prefixSum[index - 1] : 0) + charScore;
1110
}
1211

1312
const totalScore = prefixSum[stringLength - 1];

0 commit comments

Comments
 (0)