[Python3] greedy
\n\nclass Solution:\n    def uniqueLetterString(self, s: str) -> int:\n        locs = [[-1] for _ in range(26)]\n        for i, x in enumerate(s): locs[ord(x)-6
\n```\nclass Solution:\n    def uniqueLetterString(self, s: str) -> int:\n        locs = [[-1] for _ in range(26)]\n        for i, x in enumerate(s): locs[ord(x)-65].append(i)\n        \n        ans = 0 \n        for i in range(26): \n            locs[i].append(len(s))\n            for k in range(1, len(locs[i])-1): \n                ans += (locs[i][k] - locs[i][k-1]) * (locs[i][k+1] - locs[i][k])\n        return ans \n```
['Python3']