We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c850909 commit 2b9a89bCopy full SHA for 2b9a89b
1915-number-of-wonderful-substrings.js
@@ -1,3 +1,32 @@
1
+/**
2
+ * @param {string} word
3
+ * @return {number}
4
+ */
5
+const wonderfulSubstrings = function(word) {
6
+ const n = word.length;
7
+ let mask = 0
8
+ const hash = {0: 1}, a = 'a'.charCodeAt(0)
9
+ let res = 0
10
+
11
+ for(let i = 0; i < n; i++) {
12
+ const idx = word.charCodeAt(i) - a
13
+ mask ^= (1 << idx)
14
15
+ res += hash[mask] || 0
16
+ for(let j = 0; j < 10; j++) {
17
+ const newMask = mask ^ (1 << j)
18
+ res += hash[newMask] || 0
19
+ }
20
21
+ if(hash[mask] == null) hash[mask] = 0
22
+ hash[mask]++
23
24
25
+ return res
26
+};
27
28
+// another
29
30
/**
31
* @param {string} word
32
* @return {number}
0 commit comments