I suggest to do this treatment, before go directly DP.
Shorten the original string, like reduce
The same consecutive characters won't change the result and this really help improve the efficiency.
Besides, in python, it takes only 1 line to do it:
s = ''.join(a for a, b in zip(s, '#' + s) if a != b)
or use regex
s = re.sub(r'(.)\1*', r'\1', s)
Edited after stefan's suggestion.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.