题解 | #最长回文子串#

最长回文子串

http://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af

class Solution {
public:
    //时间n的平方,空间1的方法
    bool isornot(string s){
        string ss = s;
        reverse(s.begin(), s.end());
        return s == ss;
    }
    
    int getLongestPalindrome(string A, int n) {
        // write code here
        int max = 0;
        for(int i = 0; i < n; i++){
            for(int j = i; j < n; j++){
                if(isornot(A.substr(i,j-i+1))){
                    max = max>(j-i+1)?max:(j-i+1);
                }
            }
        }
        return max;
    }
};
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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