Kodewick
Start learning →
Basic←→0 / 50

Palindrome string

#045Basics[i] != s[j]5 min

A palindrome string reads exactly the same forwards and backwards, like "level" or "abba". Write is_palindrome(s): return true if it is one, false if not. Upper and lower case are different ("Aba" is not a palindrome); an empty string or one character counts as a palindrome.

Examples
is_palindrome("level")→True
is_palindrome("ab")→False
is_palindrome("")→True
The functionbool is_palindrome(const char *s)
main.c
#include <stdbool.h>
#include <string.h>

bool is_palindrome(const char *s) {
    int i = 0;
    int j = (int)strlen(s) - 1;
    while (i < j) {
        // your code here: if the two end characters differ, it is not a palindrome
        i++;
        j--;
    }
    return true;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.