Palindrome detection, reference http://blog.csdn.net/feliciafay/article/details/16984031
The use of time complexity and relatively low spatial complexity of the dynamic programming method to detect, specific practices
Figure an even number of back character cases
Figure two odd number of back word characters case
The core is if a substring is a palindrome, if the left and right side of the palindrome to expand the same character, then the palindrome extends outward.
The implementation code is as follows
BOOLtable[ +][ +] = {false}; intSstart =0; intIlength =1; intn =s.size (); for(intILoop =0; ILoop < n; ++ILoop) {Table[iloop][iloop]=true; } for(intILoop =0; ILoop < n-1; ++ILoop) { if(S[iloop] = = s[iloop+1]) {Table[iloop][iloop+1] =true; Sstart=ILoop; Ilength=2; } } for(intlen=3; Len <= N; ++Len) { for(inti =0; I < N-len +1; ++i) {intj = len + i-1; if(S[i] = = S[j] && table[i+1][j-1]) {Table[i][j]=true; Sstart=i; Ilength=Len; } } } returnS.substr (Sstart, ilength);
Leetcode the longest palindrome substring