Skip to content

Commit 8b4dd4e

Browse files
committed
https://leetcode.cn/problems/count-pairs-of-similar-strings
1 parent 63092ef commit 8b4dd4e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/count-pairs-of-similar-strings
49+
4850
https://leetcode.cn/problems/cycle-length-queries-in-a-tree
4951

5052
https://leetcode.cn/problems/two-sum-iii-data-structure-design/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function similarPairs(words: string[]): number {
2+
const cnt = new Map<number, number>();
3+
let ans = 0;
4+
for (const s of words) {
5+
let mask = 0;
6+
7+
for (const c of s) {
8+
mask |= 1 << (c.charCodeAt(0) - "a".charCodeAt(0));
9+
}
10+
ans += cnt.get(mask) ?? 0;
11+
cnt.set(mask, (cnt.get(mask) ?? 0) + 1);
12+
}
13+
return ans;
14+
}
15+
export default similarPairs;

0 commit comments

Comments
 (0)