“c0001a2433c1058ebfd21df22fe0f86146f16610”上不存在“paddle/fluid/git@gitcode.net:paddlepaddle/Paddle.git”
solution.cpp 610 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
class Solution
{
public:
	string longestPalindrome(string s)
	{
		int ti = 0, maxlen = 0, i, t;
		for (i = 0; s[i]; i++)
		{
			t = 1;
			while (t <= i && s[i + t])
			{
				if (s[i + t] == s[i - t])
					t++;
				else
					break;
			}
			t--;
			if (2 * t + 1 > maxlen)
			{
				ti = i - t;
				maxlen = 2 * t + 1;
			}
		}
		for (i = 0; s[i]; i++)
		{
			t = 1;
			while (t <= i + 1 && s[i + t])
			{
				if (s[i - t + 1] == s[i + t])
					t++;
				else
					break;
			}
			t--;
			if (2 * t > maxlen)
			{
				ti = i - t + 1;
				maxlen = 2 * t;
			}
		}
		s[ti + maxlen] = 0;
		return s.c_str() + ti;
	}
};