File tree 3 files changed +49
-0
lines changed
solution/2500-2599/2506.Count Pairs Of Similar Strings
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,24 @@ impl Solution {
170
170
}
171
171
```
172
172
173
+ ### ** TypeScript**
174
+
175
+ ``` ts
176
+ function similarPairs(words : string []): number {
177
+ let ans = 0 ;
178
+ const cnt: Map <number , number > = new Map ();
179
+ for (const w of words ) {
180
+ let v = 0 ;
181
+ for (let i = 0 ; i < w .length ; ++ i ) {
182
+ v |= 1 << (w .charCodeAt (i ) - ' a' .charCodeAt (0 ));
183
+ }
184
+ ans += cnt .get (v ) || 0 ;
185
+ cnt .set (v , (cnt .get (v ) || 0 ) + 1 );
186
+ }
187
+ return ans ;
188
+ }
189
+ ```
190
+
173
191
### ** ...**
174
192
175
193
```
Original file line number Diff line number Diff line change @@ -155,6 +155,24 @@ impl Solution {
155
155
}
156
156
```
157
157
158
+ ### ** TypeScript**
159
+
160
+ ``` ts
161
+ function similarPairs(words : string []): number {
162
+ let ans = 0 ;
163
+ const cnt: Map <number , number > = new Map ();
164
+ for (const w of words ) {
165
+ let v = 0 ;
166
+ for (let i = 0 ; i < w .length ; ++ i ) {
167
+ v |= 1 << (w .charCodeAt (i ) - ' a' .charCodeAt (0 ));
168
+ }
169
+ ans += cnt .get (v ) || 0 ;
170
+ cnt .set (v , (cnt .get (v ) || 0 ) + 1 );
171
+ }
172
+ return ans ;
173
+ }
174
+ ```
175
+
158
176
### ** ...**
159
177
160
178
```
Original file line number Diff line number Diff line change
1
+ function similarPairs ( words : string [ ] ) : number {
2
+ let ans = 0 ;
3
+ const cnt : Map < number , number > = new Map ( ) ;
4
+ for ( const w of words ) {
5
+ let v = 0 ;
6
+ for ( let i = 0 ; i < w . length ; ++ i ) {
7
+ v |= 1 << ( w . charCodeAt ( i ) - 'a' . charCodeAt ( 0 ) ) ;
8
+ }
9
+ ans += cnt . get ( v ) || 0 ;
10
+ cnt . set ( v , ( cnt . get ( v ) || 0 ) + 1 ) ;
11
+ }
12
+ return ans ;
13
+ }
You can’t perform that action at this time.
0 commit comments