题解 | #回文子串的数量#

回文子串的数量

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
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务