C++ Easy to understand
We can solve this problem using dynamic programming.\nLet\'s say dp[i] denotes the sum of which the count of unique characters for all possible substrings endin
We can solve this problem using dynamic programming.\nLet\'s say dp[i] denotes the sum of which the count of unique characters for all possible substrings ending at index i. For each index i, we have following recurrence relation:\n* dp[i] = dp[i-1] + (# of substrings ending at index i - 1 which doesn\'t contain s[i]) - (# of substrings ending at index i - 1 which contains s[i] only once) + 1\n\n```\nclass Solution {\npublic:\n  int uniqueLetterString(string s) {\n    int a[26]{}, b[26]{};\n    int cur = 1, res = 1;\n    const int n = s.length();\n    for (int i = 1; i < n; ++i) {\n      #pragma GCC unroll 26\n      for (int j = 0; j < 26; ++j) {\n        char c = char(j + \'A\');\n        if (c == s[i - 1]) {\n          b[j] = a[j] + 1;\n          a[j] = 0;\n        } else {\n          a[j] = a[j] + 1;\n        }\n      }\n      cur = cur + a[s[i] - \'A\'] - b[s[i] - \'A\'] + 1;\n      res += cur;\n    }\n    return res;\n  }\n};\n```\n\n\n
['C']