Answers for "C# program to find the longest Palindrome in a string."

C#
0

C# Check whether the String is a palindrome or not.

return myString.SequenceEqual(myString.Reverse());
Posted by: Guest on February-25-2021
0

C# Check whether the String is a palindrome or not.

var original = "ankYkna";
var reversed = new string(original.Reverse().ToArray());
var palindrom = original == reversed;
Posted by: Guest on February-25-2021
0

C# program to find the longest Palindrome in a string.

public static int LongestPalindrome(string seq)
    {
        int Longest = 0;
        List<int> l = new List<int>();
        int i = 0;
        int palLen = 0;
        int s = 0;
        int e = 0;
        while (i<seq.Length)
        {
            if (i > palLen && seq[i-palLen-1] == seq[i])
            {
                palLen += 2;
                i += 1;
                continue;
            }
            l.Add(palLen);
            Longest = Math.Max(Longest, palLen);
            s = l.Count - 2;
            e = s - palLen;
            bool found = false;
            for (int j = s; j > e; j--)
            {
                int d = j - e - 1;
                if (l[j] == d)
                {
                    palLen = d;
                    found = true;
                    break;
                }
                l.Add(Math.Min(d, l[j]));
            }
            if (!found)
            {
                palLen = 1;
                i += 1;
            }
        }
        l.Add(palLen);
        Longest = Math.Max(Longest, palLen);
        return Longest;
    }
Posted by: Guest on February-25-2021

Code answers related to "C# program to find the longest Palindrome in a string."

C# Answers by Framework

Browse Popular Code Answers by Language