Pergunta de entrevista da empresa eBay

How do you check if a string is palindrome or not?

Respostas da entrevista

Sigiloso

15 de abr. de 2016

private static boolean checkPaliandrom(String s1) { for(int i=0; i<=s1.length()/2;i++) { if(s1.charAt(i) != s1.charAt(s1.length()-i-1)) return false; } return true; }

1

Sigiloso

20 de mar. de 2016

One of the best solutions in my opinion (simple and readable) is using a stack to reverse the string (can also be done by a recursive reversal method) and then check if it is the same as the original: in Java: public static boolean isPalindrome(String str) { // Just cleaning up in case of white spaces - Might be considered as a palindrome anyway depending on the question definition str = str.replace(" ", ""); Stack stack = new Stack