1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class Solution { public: long long appealSum(string s) { int n = s.size(); long long ans = 0L, sum = 0L; vector<int> pos(26, -1); for (int i = 0; i < n; ++i) { int c = s[i] - 'a'; sum += i - pos[c]; ans += sum; pos[c] = i; } return ans; } };
|