We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1e058a8 commit 47cdc19Copy full SHA for 47cdc19
2262-total-appeal-of-a-string.js
@@ -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
23
/**
24
* @param {string} s
25
* @return {number}
0 commit comments