Empresa engajada
Write a method to compute if a string is a palindrome, disregarding spaces.
Sigiloso
isPalidrome(String s) { removeSpaces(s); String r = reverseString(s); if (r == s) then return True; Otherwise return False; }
bool isPalindrom(char s[]) { int start = 0, length, end; length = end = strlen(s); if(end<2) { return false; } end--; while(start
In Java: private static boolean isPalindrome(String str) { int leftIndex = 0; int rightIndex = str.length() - 1; while(leftIndex < rightIndex) { if (str.charAt(leftIndex) == ' ') { leftIndex++; continue; } if (str.charAt(rightIndex) == ' ') { rightIndex--; continue; } if (str.charAt(leftIndex) != str.charAt(rightIndex)) { return false; } leftIndex++; rightIndex--; } return true; } N/2 iterations for characters + N iterations for whitespaces = O(N) complexity
Fique por dentro de todas as oportunidades e dicas internas seguindo as empresas de seus sonhos.
Comece a buscar vagas para receber atualizações e recomendações personalizadas.