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 413c074 commit bbe8acaCopy full SHA for bbe8aca
1915. Number of Wonderful Substrings
@@ -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