Empresa engajada
Complete the C function (body) that uses recursion to determine if the string is a palindrome
Sigiloso
int isPalin(char *str){ int l = strlen(str); return isPalinHelper(str,0,l-1); } int isPalinHelper(char *str,int i,int j){ if(i
#include #include int palindrome(const char* head,const char* tail) { int val; if (head >= tail) return 1; return (palindrome(head+1,tail-1) && (*tail == *head)); } int check_palindrome (const char* str) { const char* tail = str + strlen(str) - 1; const char* head = str; return palindrome(head,tail); } int main(int argc, void* argv[] ) { if (check_palindrome (argv[1])) printf("true\n"); else printf("false\n"); }
bool palindrome(char* str, int len) { if(len<=1) return true; if(len == 2) if(str[0] == str[1]) return true; return (str[0] == str[len-1]) && palindrome(str+1, len-2); }
At my previous solution, please ignore the local variable int val at the palindrome function
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.