Check if a string is a palindrome

后端 未结 30 1479
星月不相逢
星月不相逢 2020-11-28 08:59

I have a string as input and have to break the string in two substrings. If the left substring equals the right substring then do some logic.

How can I do this?

30条回答
  •  攒了一身酷
    2020-11-28 09:28

    public static bool palindrome(string t)
        {
            int i = t.Length;
            for (int j = 0; j < i / 2; j++)
            {
                if (t[j] == t[i - j-1])
                {
                    continue;
                }
                else
                {
                    return false;
                    break;
                }
            }
            return true;
        }
    

提交回复
热议问题