Skip to content

Commit d98f5fc

Browse files
authored
Update 2262.Total-Appeal-of-A-String.cpp
1 parent fb5203d commit d98f5fc

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Hash/2262.Total-Appeal-of-A-String/2262.Total-Appeal-of-A-String.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@ class Solution {
22
public:
33
long long appealSum(string s)
44
{
5-
vector<vector<int>>pos(26);
5+
vector<int>pos(26, -1);
66
long long result=0;
77
for (int i=0; i<s.size(); i++)
88
{
9-
pos[s[i]-'a'].push_back(i);
9+
pos[s[i]-'a'] = i;
1010
for (int i=0; i<26; i++)
1111
{
12-
if (pos[i].size()>=1)
13-
{
14-
int k = pos[i].size();
15-
result+=(long long)pos[i][k-1]+1;
16-
}
12+
if (pos[i]!=-1)
13+
result+=(long long)pos[i]+1;
1714
}
1815
}
19-
return result;
20-
16+
return result;
2117
}
2218
};

0 commit comments

Comments
 (0)