Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int LongestPolindrome(string st)
- {
- int maxLength = 0, currentLength;
- int i = 0, nextI, k;
- while (i < st.Length)
- {
- currentLength = 1;
- k = 1;
- nextI = st.IndexOf('*', i);
- if (nextI < 0)
- nextI = st.Length - 1;
- while (nextI >= k && nextI + k < st.Length && st[nextI - k] == st[nextI + k])
- {
- k++;
- currentLength += 2;
- }
- if (currentLength > maxLength)
- maxLength = currentLength;
- i = nextI + 1;
- }
- return maxLength;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement