Skip to content

Commit 63263ef

Browse files
authored
Create 1915. Number of Wonderful Substrings (#469)
2 parents 413c074 + bbe8aca commit 63263ef

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

1915. Number of Wonderful Substrings

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
long long wonderfulSubstrings(string word) {
4+
unordered_map<int, int> count;
5+
int mask = 0;
6+
count[0] = 1;
7+
long long result = 0;
8+
for(char c : word) {
9+
mask ^= 1 << (c - 'a');
10+
result += count[mask];
11+
for(int i = 0; i < 10; i++) {
12+
result += count[mask ^ (1 << i)];
13+
}
14+
count[mask]++;
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)