You are viewing a single comment's thread. Return to all comments →
def shortPalindrome(s): arr1 = [0]*26 arr2 = [[0]*26 for i in range(26)] arr3 = [0]*26 ans = 0 for i in range(len(s)): idx = ord(s[i]) - ord('a') ans += arr3[idx] for j in range(26): arr3[j] += arr2[j][idx] for j in range(26): arr2[j][idx] += arr1[j] arr1[idx] += 1 return ans % (10**9+7)
Seems like cookies are disabled on this browser, please enable them to open this website
Short Palindrome
You are viewing a single comment's thread. Return to all comments →