File tree Expand file tree Collapse file tree 1 file changed +20
-20
lines changed
count-unique-characters-of-all-substrings-of-a-given-string Expand file tree Collapse file tree 1 file changed +20
-20
lines changed Original file line number Diff line number Diff line change 1
- function uniqueLetterString ( s : string ) : number {
2
- const index = new Map < string , number [ ] > ( ) ;
3
-
4
- for ( const [ i , c ] of Array . prototype . entries . call ( s ) ) {
5
- const arr = index . get ( c ) ?? [ - 1 ] ;
6
- arr . push ( i ) ;
7
- index . set ( c , arr ) ;
8
- }
9
- let res = 0 ;
10
-
11
- for ( const arr of index . values ( ) ) {
12
- arr . push ( s . length ) ;
13
-
14
- for ( let i = 1 ; i < arr . length - 1 ; i ++ ) {
15
- res += ( arr [ i ] - arr [ i - 1 ] ) * ( arr [ i + 1 ] - arr [ i ] ) ;
16
- }
17
- }
18
- return res ;
19
- }
20
- export default uniqueLetterString ;
1
+ function uniqueLetterString ( s : string ) : number {
2
+ const index = new Map < string , number [ ] > ( ) ;
3
+
4
+ for ( const [ i , c ] of Array . prototype . entries . call ( s ) ) {
5
+ const arr = index . get ( c ) ?? [ - 1 ] ;
6
+ arr . push ( i ) ;
7
+ index . set ( c , arr ) ;
8
+ }
9
+ let res = 0 ;
10
+
11
+ for ( const arr of index . values ( ) ) {
12
+ arr . push ( s . length ) ;
13
+
14
+ for ( let i = 1 ; i < arr . length - 1 ; i ++ ) {
15
+ res += ( arr [ i ] - arr [ i - 1 ] ) * ( arr [ i + 1 ] - arr [ i ] ) ;
16
+ }
17
+ }
18
+ return res ;
19
+ }
20
+ export default uniqueLetterString ;
You can’t perform that action at this time.
0 commit comments