Skip to content

Commit 58d158c

Browse files
authored
Create 828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String.cpp
1 parent e281d9e commit 58d158c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
long long M = pow(10,9)+7;
3+
public:
4+
int uniqueLetterString(string S)
5+
{
6+
vector<vector<int>>pos(26);
7+
int result=0;
8+
for (int i=0; i<S.size(); i++)
9+
{
10+
pos[S[i]-'A'].push_back(i);
11+
for (int i=0; i<26; i++)
12+
{
13+
if (pos[i].size()==1)
14+
result+=pos[i][0]+1;
15+
else if (pos[i].size()>1)
16+
{
17+
int k = pos[i].size();
18+
result+=pos[i][k-1]-pos[i][k-2];
19+
}
20+
result = result%M;
21+
}
22+
}
23+
return result;
24+
}
25+
26+
};

0 commit comments

Comments
 (0)