找出一个字符串中所有大于1的回文串数量,2021网易算法岗笔试,AC100%
思路:对于给定的字符串,暴力求解出所有的字串,然后判断每个字串是否为回文串且长度大于1,是的花计数加1。
class Solution():
'''
找出一个字符串中所有大于1的回文串数量
'''
def subString(self, s):
cnt = 0
for x in range(len(s)):
for i in range(len(s) - x):
if s[i:i+x+1] == s[i:i+x+1][::-1] and len(s[i:i+x+1]) > 1:
cnt += 1
return cnt
s = Solution()
line = input()
print(s.subString(line))