File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
solution/2200-2299/2262.Total Appeal of A String Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,17 @@ func appealSum(s string) int64 {
148
148
### ** TypeScript**
149
149
150
150
``` ts
151
-
151
+ function appealSum(s : string ): number {
152
+ const n = s .length ;
153
+ let dp = new Array (n + 1 ).fill (0 );
154
+ const hashMap = new Map ();
155
+ for (let i = 0 ; i < n ; i ++ ) {
156
+ const c = s .charAt (i );
157
+ dp [i + 1 ] = dp [i ] + i + 1 - (hashMap .get (c ) || 0 );
158
+ hashMap .set (c , i + 1 );
159
+ }
160
+ return dp .reduce ((a , c ) => a + c , 0 );
161
+ };
152
162
```
153
163
154
164
### ** ...**
Original file line number Diff line number Diff line change @@ -131,7 +131,17 @@ func appealSum(s string) int64 {
131
131
### ** TypeScript**
132
132
133
133
``` ts
134
-
134
+ function appealSum(s : string ): number {
135
+ const n = s .length ;
136
+ let dp = new Array (n + 1 ).fill (0 );
137
+ const hashMap = new Map ();
138
+ for (let i = 0 ; i < n ; i ++ ) {
139
+ const c = s .charAt (i );
140
+ dp [i + 1 ] = dp [i ] + i + 1 - (hashMap .get (c ) || 0 );
141
+ hashMap .set (c , i + 1 );
142
+ }
143
+ return dp .reduce ((a , c ) => a + c , 0 );
144
+ };
135
145
```
136
146
137
147
### ** ...**
Original file line number Diff line number Diff line change
1
+ function appealSum ( s : string ) : number {
2
+ const n = s . length ;
3
+ let dp = new Array ( n + 1 ) . fill ( 0 ) ;
4
+ const hashMap = new Map ( ) ;
5
+ for ( let i = 0 ; i < n ; i ++ ) {
6
+ const c = s . charAt ( i ) ;
7
+ dp [ i + 1 ] = dp [ i ] + i + 1 - ( hashMap . get ( c ) || 0 ) ;
8
+ hashMap . set ( c , i + 1 ) ;
9
+ }
10
+ return dp . reduce ( ( a , c ) => a + c , 0 ) ;
11
+ } ;
You can’t perform that action at this time.
0 commit comments