Skip to content

Commit 3f497fc

Browse files
authored
Update 828-unique-letter-string.js
1 parent aba5c1c commit 3f497fc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

828-unique-letter-string.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* @param {string} S
3+
* @return {number}
4+
*/
5+
const uniqueLetterString = function(S) {
6+
const s = S.split('')
7+
let res = 0
8+
for (let n = S.length, i = 0, l = 0, r = 0; i < n; i++) {
9+
for (l = i - 1; l >= 0 && s[l] != s[i]; l--);
10+
for (r = i + 1; r < n && s[r] != s[i]; r++);
11+
res += (r - i) * (i - l)
12+
}
13+
return res % (10 ** 9 + 7)
14+
}
15+
16+
// another
17+
118
/**
219
* @param {string} S
320
* @return {number}

0 commit comments

Comments
 (0)