Skip to content

Commit 47cdc19

Browse files
authored
Update 2262-total-appeal-of-a-string.js
1 parent 1e058a8 commit 47cdc19

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2262-total-appeal-of-a-string.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var appealSum = function (s) {
6+
const pos = Array(26).fill(-1)
7+
let ans = 0
8+
const n = s.length
9+
const a = 'a'.charCodeAt(0)
10+
for (let i = 0; i < n; i++) {
11+
let tmp = n - i
12+
if (pos[s.charCodeAt(i) - a] !== -1)
13+
tmp += (i - pos[s.charCodeAt(i) - a] - 1) * (n - i)
14+
else tmp += i * (n - i)
15+
ans += tmp
16+
pos[s.charCodeAt(i) - a] = i
17+
}
18+
return ans
19+
}
20+
21+
// another
22+
123
/**
224
* @param {string} s
325
* @return {number}

0 commit comments

Comments
 (0)