题解 | #滑动窗口的最大值#
滑动窗口的最大值
http://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
class Solution {
public:
int getLongestPalindrome(string str, int n) {
// write code here
int res = 0;
for(int i = 0; i < n; i++){
int l = i - 1, r = i + 1;
while(l >= 0 && r < n && str[l] == str[r]) l--, r++;
res = max(res, r - l - 1);
l = i, r = i + 1;
while(l >= 0 && r < n && str[l] == str[r]) l--, r++;
res = max(res, r - l - 1);
}
return res;
}
};