forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 1915.Number-of-Wonderful-Substrings.cpp
- Loading branch information
1 parent
2377226
commit 941984c
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
Hash/1915.Number-of-Wonderful-Substrings/1915.Number-of-Wonderful-Substrings.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |