Skip to content

Commit 067586b

Browse files
authored
Create 1915-number-of-wonderful-substrings.js
1 parent 8c54083 commit 067586b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {string} word
3+
* @return {number}
4+
*/
5+
const asi = (c) => c.charCodeAt();
6+
const wonderfulSubstrings = (s) => {
7+
let res = 0;
8+
let f = Array(2 ** 10).fill(0);
9+
f[0] = 1; // count array
10+
let cur = res = 0;
11+
for (const c of s) {
12+
cur ^= 1 << asi(c) - 97; // get Hash (the set bit for a character.), update prefix parity
13+
res += f[cur];
14+
for (let i = 0; i < 10; i++) { // a ~ j
15+
res += f[cur ^ 1 << i]; // 1 << i get Hash
16+
}
17+
f[cur]++;
18+
}
19+
return res;
20+
};

0 commit comments

Comments
 (0)