题解 | #回文子串的数量#
回文子串的数量
http://www.nowcoder.com/practice/3e8b48c812864b0eabba0b8b25867738
由于字符串长度 <= 1000, 可直接采用暴力解法
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param str string字符串
# @return int整型
#
class Solution:
def Substrings(self , s: str) -> int:
# write code here
res = 0
for i in range(len(s)):
for j in range(i, len(s)):
if s[i:j + 1] == s[i:j + 1][::-1]:
res += 1
return res


查看17道真题和解析