2262. Total Appeal of A String

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2262

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