-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfd.txt
34 lines (34 loc) · 910 Bytes
/
fd.txt
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
class Solution {
public:
string longestPalindrome(string s) {
int L = s.size(),num = 1,begin = 0,end = 0;
string re = "";
for(int i = 1;i<L;++i)
{
int j = i - 1,k = i+1;
int numtmp = 1;
while(j >= 0 && k<=L-1)
{
if(s[j] == s[k])
{
numtmp += 2;
if(numtmp > num)
{
num = numtmp;
begin = j;
end = k;
}
}
--j;
++k;
}
}
if(num != 1)
{
for(int i = begin;i <=end;++i)
re += s[i];
}
else return (re += s[0]);
return re;
}
};