File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
count-pairs-of-similar-strings Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/count-pairs-of-similar-strings
49
+
48
50
https://leetcode.cn/problems/cycle-length-queries-in-a-tree
49
51
50
52
https://leetcode.cn/problems/two-sum-iii-data-structure-design/
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments