Java实现:
public static boolean isPalindrome(String s)
{
int N =s.length();
for (int i = 0; i < N/2; i++)
if (s.chaAt(i) != s.charAt(N-1-i))
return false;
return true;
}
Python实现:
def isPalindrome(s):
for i in range(int(len(s)/2)):// 之所以要除以2,是为了避免二次重复比较,增加开销
return s[i] == s[-i-1]