Skip to content

Commit 13058d6

Browse files
authored
feat: add typescript solution to lc problem: No.1915.Number of Wonderful Substrings (doocs#483)
1 parent 8a14a33 commit 13058d6

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

solution/1900-1999/1915.Number of Wonderful Substrings/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171

7272
<!-- 这里可写通用的实现逻辑 -->
7373

74+
状态压缩 + 前缀和
75+
7476
<!-- tabs:start -->
7577

7678
### **Python3**
@@ -89,6 +91,32 @@
8991

9092
```
9193

94+
### **JavaScript**
95+
96+
```js
97+
/**
98+
* @param {string} word
99+
* @return {number}
100+
*/
101+
var wonderfulSubstrings = function(word) {
102+
let n = 1 << 10;
103+
let counts = new Array(n).fill(0);
104+
counts[0] = 1;
105+
let pre = 0;
106+
let ans = 0;
107+
for (let c of word) {
108+
let cur = c.charCodeAt(0) - 'a'.charCodeAt(0);
109+
pre ^= (1 << cur);
110+
ans += counts[pre];
111+
for (let i = 1; i < n; i <<= 1) {
112+
ans += counts[pre ^ i];
113+
}
114+
++counts[pre];
115+
}
116+
return ans;
117+
};
118+
```
119+
92120
### **...**
93121

94122
```

solution/1900-1999/1915.Number of Wonderful Substrings/README_EN.md

+26
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@
7979

8080
```
8181

82+
### **JavaScript**
83+
84+
```js
85+
/**
86+
* @param {string} word
87+
* @return {number}
88+
*/
89+
var wonderfulSubstrings = function(word) {
90+
let n = 1 << 10;
91+
let counts = new Array(n).fill(0);
92+
counts[0] = 1;
93+
let pre = 0;
94+
let ans = 0;
95+
for (let c of word) {
96+
let cur = c.charCodeAt(0) - 'a'.charCodeAt(0);
97+
pre ^= (1 << cur);
98+
ans += counts[pre];
99+
for (let i = 1; i < n; i <<= 1) {
100+
ans += counts[pre ^ i];
101+
}
102+
++counts[pre];
103+
}
104+
return ans;
105+
};
106+
```
107+
82108
### **...**
83109

84110
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {string} word
3+
* @return {number}
4+
*/
5+
var wonderfulSubstrings = function(word) {
6+
let n = 1 << 10;
7+
let counts = new Array(n).fill(0);
8+
counts[0] = 1;
9+
let pre = 0;
10+
let ans = 0;
11+
for (let c of word) {
12+
let cur = c.charCodeAt(0) - 'a'.charCodeAt(0);
13+
pre ^= (1 << cur);
14+
ans += counts[pre];
15+
for (let i = 1; i < n; i <<= 1) {
16+
ans += counts[pre ^ i];
17+
}
18+
++counts[pre];
19+
}
20+
return ans;
21+
};

0 commit comments

Comments
 (0)