2083. Substrings That Begin and End With the Same Letter

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2083

class Solution:
    def numberOfSubstrings(self, s: str) -> int:
        cnt = Counter()
        res = 0
        for c in s:
            cnt[c] += 1
            res += cnt[c]
        return res