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 2377226 commit 941984cCopy full SHA for 941984c
Hash/1915.Number-of-Wonderful-Substrings/1915.Number-of-Wonderful-Substrings.cpp
@@ -0,0 +1,26 @@
1
+typedef long long ll;
2
+class Solution {
3
+public:
4
+ long long wonderfulSubstrings(string word)
5
+ {
6
+ int n = word.size();
7
+ int state = 0;
8
+ vector<int>count(1<<10);
9
+ count[0]+=1;
10
+
11
+ ll ret = 0;
12
+ for (int i=0; i<n; i++)
13
14
+ int j = word[i]-'a';
15
+ state ^= (1<<j);
16
17
+ ret += count[state];
18
19
+ for (int j=0; j<10; j++)
20
+ ret += count[state ^ (1<<j)];
21
22
+ count[state]++;
23
+ }
24
+ return ret;
25
26
+};
0 commit comments