面试题目:判定一个字符串是不是回文,例如:“ABA”,"ABBA"
代码:
public static void Pa(string n)
{
if (n == null)
{
throw new Exception("It is null");
}
string s = Convert.ToString(n);
Console.WriteLine(n);
int half = s.Length / 2;
int len = s.Length;
for (int i = 0; i < half; i++)
{
if (s[i] != s[len - i - 1])
{
Console.WriteLine("Congratulations,It is not a palindrome");
return;
}
}
Console.WriteLine("Sorry,It is a palindrome");
}
{
if (n == null)
{
throw new Exception("It is null");
}
string s = Convert.ToString(n);
Console.WriteLine(n);
int half = s.Length / 2;
int len = s.Length;
for (int i = 0; i < half; i++)
{
if (s[i] != s[len - i - 1])
{
Console.WriteLine("Congratulations,It is not a palindrome");
return;
}
}
Console.WriteLine("Sorry,It is a palindrome");
}
以上是昨天参加中软国际面试时候的一道题目,我是按上面的思路和代码写的,但是面试官说有问题,注:面试官是一个QA
有哪位牛人知道问题出在哪里,欢迎指正。