Question d’entretien chez Zocdoc

Write a program to detect if a String is a palidrome

Réponses aux questions d'entretien

Utilisateur anonyme

13 oct. 2015

Keep an index of the first and last characters in the string. Compare the characters at these indices, then shift the indices (increase the first index by 1, decrease the second index by 2). From StackOverflow: public static boolean istPalindrom(char[] word){ int i1 = 0; int i2 = word.length - 1; while (i2 > i1) { if (word[i1] != word[i2]) { return false; } ++i1; --i2; } return true; } If the interviewer requests that the function take a string then just use String.toCharArray

Utilisateur anonyme

25 févr. 2016

Depending on which libraries you are allowed to use, you could do something like this: public static boolean isPalindrome(String input) { StringBuilder sb = new StringBuilder(input); return sb.reverse().toString().equals(input); }