2262. Total Appeal of A String
On This Page
class Solution:
def appealSum(self, s: str) -> int:
res = t = 0
pos = [-1] * 26
for i, c in enumerate(s):
c = ord(c) - ord('a')
t += i - pos[c]
res += t
pos[c] = i
return res