Skip to content

Commit eaa6853

Browse files
authored
feat: add ts solution to lc problem: No.2506 (#1297)
1 parent 923471e commit eaa6853

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/2500-2599/2506.Count Pairs Of Similar Strings/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,24 @@ impl Solution {
170170
}
171171
```
172172

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+
173191
### **...**
174192

175193
```

solution/2500-2599/2506.Count Pairs Of Similar Strings/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ impl Solution {
155155
}
156156
```
157157

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+
158176
### **...**
159177

160178
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

0 commit comments

Comments
 (0)