Skip to content

Commit

Permalink
Create 1915.Number-of-Wonderful-Substrings.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Jun 28, 2021
1 parent 2377226 commit 941984c
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
typedef long long ll;
class Solution {
public:
long long wonderfulSubstrings(string word)
{
int n = word.size();
int state = 0;
vector<int>count(1<<10);
count[0]+=1;

ll ret = 0;
for (int i=0; i<n; i++)
{
int j = word[i]-'a';
state ^= (1<<j);

ret += count[state];

for (int j=0; j<10; j++)
ret += count[state ^ (1<<j)];

count[state]++;
}
return ret;
}
};

0 comments on commit 941984c

Please sign in to comment.