Advertisement
AvengersAssemble

Ex23

Feb 13th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1.         public static int LongestPolindrome(string st)
  2.         {
  3.             int maxLength = 0, currentLength;
  4.             int i = 0, nextI, k;
  5.             while (i < st.Length)
  6.             {
  7.                
  8.                 currentLength = 1;
  9.                 k = 1;
  10.                 nextI = st.IndexOf('*', i);
  11.                 if (nextI < 0)
  12.                     nextI = st.Length - 1;
  13.                 while (nextI >= k && nextI + k < st.Length && st[nextI - k] == st[nextI + k])
  14.                 {
  15.                     k++;
  16.                     currentLength += 2;
  17.                 }
  18.                 if (currentLength > maxLength)
  19.                     maxLength = currentLength;
  20.                 i = nextI + 1;
  21.             }
  22.             return maxLength;
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement