Skip to content

Commit 941984c

Browse files
authored
Create 1915.Number-of-Wonderful-Substrings.cpp
1 parent 2377226 commit 941984c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)